@thinkingai/ae-cli 6.1.33 → 6.1.34

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.
Files changed (85) hide show
  1. package/README.md +2 -2
  2. package/README.zh.md +2 -6
  3. package/cli-installation-guide.md +14 -4
  4. package/dist/{ai-monitor-OHTSU6SV.js → ai-monitor-TVRFVZBH.js} +10 -9
  5. package/dist/ai-monitor.js +17 -16
  6. package/dist/{auth-2MOK4OI6.js → auth-JAXLMPBB.js} +25 -317
  7. package/dist/{automation-6L6IAYRK.js → automation-OQ647CSW.js} +7 -6
  8. package/dist/{capability-EMIHQJA3.js → capability-2Z4ZXTPD.js} +18 -16
  9. package/dist/chunk-2H3SFJE3.js +344 -0
  10. package/dist/{chunk-RC3PPCYD.js → chunk-3PZNM5KN.js} +3 -3
  11. package/dist/chunk-3ZQY7SLZ.js +147 -0
  12. package/dist/{chunk-NNK3JBH4.js → chunk-6E6HCTP2.js} +2 -2
  13. package/dist/{local-data-upload-client-YTWMAAGE.js → chunk-6IUTXRAD.js} +32 -4
  14. package/dist/{chunk-VLOGOM7N.js → chunk-CYZV5AXW.js} +8 -5
  15. package/dist/{chunk-O45NOIWR.js → chunk-DE5XHQQ6.js} +2 -2
  16. package/dist/{chunk-KD5UC33N.js → chunk-E5CJI7L3.js} +7 -5
  17. package/dist/{chunk-UCMO4LKL.js → chunk-EQMGH32F.js} +2 -2
  18. package/dist/{chunk-E3ONSFUN.js → chunk-FNACCKQR.js} +211 -12
  19. package/dist/{chunk-2I5SZ5DS.js → chunk-GD5JSAGV.js} +2 -2
  20. package/dist/{chunk-EFGUBGA6.js → chunk-GYODT7C4.js} +1 -1
  21. package/dist/chunk-HBI7IQH3.js +1207 -0
  22. package/dist/{chunk-AMURHMS3.js → chunk-IGU3R2JD.js} +4 -4
  23. package/dist/{chunk-YE6MJB5V.js → chunk-IWMDPHMI.js} +3 -3
  24. package/dist/{chunk-LFJ7N36I.js → chunk-L7MT53VM.js} +5 -3
  25. package/dist/{chunk-HIMOBNEY.js → chunk-LXRALNNA.js} +2 -2
  26. package/dist/{chunk-BQFLABJQ.js → chunk-M2OCZRVX.js} +7 -5
  27. package/dist/{chunk-R2SVAO4G.js → chunk-MTK4ZE7W.js} +3 -143
  28. package/dist/{chunk-7DHSB3FL.js → chunk-NK5PS5X7.js} +3 -3
  29. package/dist/{chunk-HQED4YB4.js → chunk-NPH5J65M.js} +1 -1
  30. package/dist/{chunk-EWVEAERM.js → chunk-Q764EZND.js} +78 -72
  31. package/dist/chunk-QOJXLXDJ.js +55 -0
  32. package/dist/{chunk-THTROEGD.js → chunk-QPUPWGZ3.js} +1 -1
  33. package/dist/{chunk-XZDKAR4N.js → chunk-RLPMXKDQ.js} +8921 -10119
  34. package/dist/{chunk-DWAG2QJM.js → chunk-S74XV3A6.js} +4 -4
  35. package/dist/{chunk-COOMXFUG.js → chunk-SHB7A2JE.js} +3 -3
  36. package/dist/{chunk-PLNS5J33.js → chunk-UWQXGF44.js} +17 -9
  37. package/dist/{data-integration-UNJ7EPW2.js → chunk-V6UKLIM6.js} +160 -2258
  38. package/dist/{chunk-4IQYPWCX.js → chunk-VPLRZSMY.js} +18 -10
  39. package/dist/{chunk-KA5WKR5P.js → chunk-Z6WSCIHM.js} +2 -2
  40. package/dist/{community-report-client-ULRNXLQV.js → community-report-client-5VNT6HCV.js} +4 -2
  41. package/dist/{compat-check-CADG7GND.js → compat-check-E7AQ7UCG.js} +5 -4
  42. package/dist/{config-PFD3KWQG.js → config-PGSUWIK5.js} +15 -11
  43. package/dist/{context-SOQDFZIB.js → context-Y2A6QIS3.js} +5 -4
  44. package/dist/conversion-4FR3RA45.js +16 -0
  45. package/dist/data-integration-EIF5QHYF.js +2138 -0
  46. package/dist/{evaluation-Q3AIGFOG.js → evaluation-OZM54MES.js} +6 -5
  47. package/dist/index.js +74 -51
  48. package/dist/local-data-upload-client-2U3LFD7Z.js +16 -0
  49. package/dist/{memory-HKNGUIPK.js → memory-6QMZS4HF.js} +7 -6
  50. package/dist/{metadata-GFWR5ZHC.js → metadata-7MZ3CJ2N.js} +10 -9
  51. package/dist/{model-NAKQWK4W.js → model-LEYRQKOS.js} +8 -7
  52. package/dist/{personal-semantic-preference-JCTKXLC3.js → personal-semantic-preference-SWOUNDWJ.js} +9 -8
  53. package/dist/{project-semantic-B2NWQOKK.js → project-semantic-M2DDPAMD.js} +9 -8
  54. package/dist/{sync-UQH4J4BD.js → sync-PWC63JCO.js} +16 -15
  55. package/dist/{te-agent-L6EYFQCC.js → te-agent-S7UH657Z.js} +11 -9
  56. package/dist/{te-analysis-U7NNOY66.js → te-analysis-BK6PE333.js} +281 -214
  57. package/dist/{te-community-3UQEW3KD.js → te-community-OLNTKGCW.js} +12 -10
  58. package/dist/{te-dataops-SUNYXF5G.js → te-dataops-XUWRIF5R.js} +12 -10
  59. package/dist/{te-engage-KMXZJ2KN.js → te-engage-I3I4FJOM.js} +9 -8
  60. package/dist/{te-experiment-IEYKP6VC.js → te-experiment-XSDUL4KH.js} +9 -8
  61. package/dist/{te-kb-MT3V5ZMH.js → te-kb-QFH3YLFQ.js} +15 -13
  62. package/dist/{te-system-F4ZU2HRQ.js → te-system-DB5Z3LLF.js} +7 -6
  63. package/dist/{te-team-M6E6XQ5H.js → te-team-UADF2HBO.js} +9 -8
  64. package/dist/{things-FRLBZV2Z.js → things-G2QFXDK7.js} +9 -8
  65. package/dist/{update-NULYHVE6.js → update-6I366ICW.js} +7 -8
  66. package/dist/web-runtime-3XFREWRF.js +2367 -0
  67. package/dist/{workspace-Z7L33OBQ.js → workspace-RZESYB6T.js} +7 -6
  68. package/package.json +4 -3
  69. package/skills/ae-analysis/SKILL.md +1 -1
  70. package/skills/ae-data-integration/references/ue-mapping.md +2 -0
  71. package/skills/ae-onboarding/SKILL.md +64 -0
  72. package/skills/ae-onboarding/references/business-sdk.md +8 -0
  73. package/skills/ae-onboarding/references/demo-operations.md +79 -0
  74. package/skills/ae-onboarding/references/import.md +19 -0
  75. package/skills/ae-onboarding/references/onboarding_experiment_launch.md +12 -0
  76. package/skills/ae-onboarding/references/onboarding_experiment_plan.md +14 -0
  77. package/skills/ae-onboarding/references/onboarding_growth.md +36 -0
  78. package/skills/ae-onboarding/references/onboarding_run.md +11 -0
  79. package/skills/ae-onboarding/references/onboarding_status.md +5 -0
  80. package/skills/ae-onboarding/scripts/experiment-preset.json +252 -0
  81. package/skills/ae-onboarding/scripts/experiment-requests.mjs +120 -0
  82. package/skills/ae-onboarding/scripts/generate.mjs +170 -0
  83. package/skills/ae-onboarding/scripts/resolve-experiment-preset.mjs +26 -0
  84. package/skills/ae-onboarding/scripts/web-journey.mjs +39 -0
  85. package/dist/chunk-6ZIQV5GW.js +0 -26
@@ -0,0 +1,120 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ import { isDemoAccountId, resolveExperimentPreset } from './resolve-experiment-preset.mjs';
5
+
6
+ function buildRequests({ industry, experimentType, sampleId, itemId, runId, bucketId: requestedBucketId, accountIds: requestedAccountIds, metricIds }) {
7
+ const { preset, sample, experimentType: selectedType } = resolveExperimentPreset({ industry, experimentType, sampleId, itemId });
8
+ const bucketId = requestedBucketId === undefined ? preset.audience.bucketId : requestedBucketId;
9
+ const accountIds = requestedAccountIds === undefined ? sample.followUpAccountIds : requestedAccountIds;
10
+ if (typeof runId !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,31}$/.test(runId)) {
11
+ throw new Error('runId must be the saved Demo run ID.');
12
+ }
13
+ if (bucketId !== preset.audience.bucketId) {
14
+ throw new Error('bucketId must be the preset account-ID bucket.');
15
+ }
16
+ if (!Array.isArray(accountIds) || accountIds.length < 2
17
+ || accountIds.some((id) => typeof id !== 'string' || !id.trim() || id !== id.trim())
18
+ || new Set(accountIds).size !== accountIds.length) {
19
+ throw new Error('accountIds must contain at least two distinct, verified account IDs.');
20
+ }
21
+ if (selectedType === 'checkout-recovery' && (requestedAccountIds === undefined
22
+ || !accountIds.every(id => isDemoAccountId(id, sampleId, sample.userCount)))) {
23
+ throw new Error('Checkout recovery requires the verified cohort for this Demo sample.');
24
+ }
25
+ const revenueMetricId = metricIds === undefined ? sample.netRevenueMetricId : metricIds?.secondary;
26
+ if (typeof revenueMetricId !== 'string' || !revenueMetricId.trim() || revenueMetricId !== revenueMetricId.trim()) {
27
+ throw new Error('metricIds.secondary must contain the verified net revenue metric ID.');
28
+ }
29
+
30
+ const suffix = createHash('sha256').update(runId).digest('hex').slice(0, 12);
31
+ const featureKey = `${preset.feature.keyPrefix}_${suffix}`;
32
+ const { control, treatment } = preset.arms;
33
+ const feature = {
34
+ featureKey,
35
+ displayName: `${preset.feature.displayName} (${runId})`,
36
+ type: preset.feature.type,
37
+ defaultValue: control.featureValue,
38
+ targetPlatform: preset.feature.targetPlatform,
39
+ };
40
+
41
+ const filters = {
42
+ relation: 'and',
43
+ items: [
44
+ { field: preset.metricFilters[0], operator: 'eq', values: [sampleId] },
45
+ { field: preset.metricFilters[1], operator: 'eq', values: [itemId] },
46
+ ],
47
+ };
48
+ const { role, format, ...definition } = preset.metrics.find((entry) => entry.role === 'primary');
49
+ const metric = {
50
+ metricId: `plg_primary_${suffix}`,
51
+ metricName: `Unique buyers (${runId})`,
52
+ createType: 'event',
53
+ goalDirection: 'up',
54
+ metricPurpose: 'confidence_statistics',
55
+ metricDesc: 'Unique buyers for the Demo sample and item',
56
+ format,
57
+ metricDefinition: { type: 'event', ...definition, filters },
58
+ };
59
+ if (metric.metricId === revenueMetricId) throw new Error('The two experiment metrics must have different IDs.');
60
+
61
+ const secondary = preset.metrics.find((entry) => entry.role === 'secondary');
62
+ const revenueMetric = {
63
+ metricId: revenueMetricId,
64
+ metricName: `PLG net revenue (${sampleId})`,
65
+ createType: 'event',
66
+ goalDirection: 'up',
67
+ metricPurpose: 'confidence_statistics',
68
+ metricDesc: 'Total paid order amount for the Demo sample and item',
69
+ format: secondary.format,
70
+ metricDefinition: {
71
+ type: 'event',
72
+ event: secondary.event,
73
+ aggregation: secondary.aggregation,
74
+ property: secondary.property,
75
+ filters,
76
+ },
77
+ };
78
+
79
+ const experiment = {
80
+ expName: `${preset.experiment.name} (${runId})`,
81
+ expType: preset.experiment.atlasType,
82
+ expSupposition: preset.experiment.hypothesis,
83
+ isExpSharing: 0,
84
+ bucketId,
85
+ allocation: preset.allocation,
86
+ expCycle: { cycleType: 'day', dayNum: preset.durationDays },
87
+ featureKeyList: [featureKey],
88
+ groups: [control, treatment].map((arm, index) => ({
89
+ expGroupName: arm.name,
90
+ isControl: index === 0 ? 1 : 0,
91
+ allocation: arm.allocation,
92
+ expGroupValue: JSON.stringify([arm.featureValue]),
93
+ })),
94
+ metrics: [
95
+ { metricId: metric.metricId, metricRole: role },
96
+ { metricId: revenueMetricId, metricRole: 'secondary' },
97
+ ],
98
+ targeting: {
99
+ definitionRequest: {
100
+ type: 'condition',
101
+ conditions: {
102
+ relation: 'or',
103
+ items: [...accountIds].sort().map((id) => ({
104
+ type: 'user', field: '#account_id', operator: 'eq', values: [id],
105
+ })),
106
+ },
107
+ },
108
+ },
109
+ };
110
+ return metricIds === undefined ? { feature, metric, experiment, revenueMetric } : { feature, metric, experiment };
111
+ }
112
+
113
+ try {
114
+ if (process.argv.length !== 3) throw new Error('Usage: node experiment-requests.mjs <verified-input.json>');
115
+ const input = JSON.parse(readFileSync(process.argv[2], 'utf8'));
116
+ process.stdout.write(JSON.stringify(buildRequests(input), null, 2) + '\n');
117
+ } catch (error) {
118
+ process.stderr.write(`Cannot prepare Demo experiment requests: ${error.message}\n`);
119
+ process.exitCode = 1;
120
+ }
@@ -0,0 +1,170 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { parseArgs } from 'node:util';
5
+
6
+ import { isDemoAccountId, resolveExperimentPreset } from './resolve-experiment-preset.mjs';
7
+
8
+ const dayMs = 86_400_000;
9
+ const minuteMs = 60_000;
10
+ const outcomeDelayMs = 5_000;
11
+
12
+ function main() {
13
+ const { values: args } = parseArgs({
14
+ options: Object.fromEntries([
15
+ 'phase', 'run-id', 'output-dir', 'start', 'end', 'timezone', 'experiment-id', 'control-id', 'treatment-id',
16
+ 'cohort-file', 'sample-id', 'item-id', 'industry', 'experiment-type',
17
+ ].map((name) => [name, { type: 'string' }])),
18
+ });
19
+ if (args.phase !== 'plg-experiment-today') {
20
+ throw new Error('Pass --phase plg-experiment-today for a confirmed PLG experiment.');
21
+ }
22
+ if (!/^[a-z0-9][a-z0-9_-]{0,31}$/.test(args['run-id'] ?? '') || !args['output-dir']) {
23
+ throw new Error('Pass --run-id <slug> and --output-dir <new directory>.');
24
+ }
25
+
26
+ const start = Date.parse(args.start);
27
+ const end = Date.parse(args.end);
28
+ const now = Date.now();
29
+ const earliest = now - 3 * 365 * dayMs;
30
+ const utcTimestamp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
31
+ if (!utcTimestamp.test(args.start ?? '') || !Number.isFinite(start)
32
+ || start < earliest || start > now) {
33
+ throw new Error('--start must be a UTC ISO timestamp between three years ago and now.');
34
+ }
35
+ if (!args.timezone) {
36
+ throw new Error('For plg-experiment-today, pass the project reporting timezone with --timezone.');
37
+ }
38
+ const date = reportingDate(args.timezone);
39
+ const today = date(now);
40
+ if (!utcTimestamp.test(args.end ?? '') || !Number.isFinite(end)
41
+ || start + outcomeDelayMs > end || end > now + outcomeDelayMs || date(start) !== today) {
42
+ throw new Error('For plg-experiment-today, pass an interval starting within today in the project timezone, at least 5 seconds long and ending no later than 5 seconds from now.');
43
+ }
44
+
45
+ const { 'experiment-id': experimentId, 'control-id': controlId, 'treatment-id': treatmentId } = args;
46
+ if (![experimentId, controlId, treatmentId].every((id) => id?.trim()) || controlId === treatmentId) {
47
+ throw new Error('Pass verified --experiment-id, --control-id, and --treatment-id for the saved Feature experiment.');
48
+ }
49
+ generatePlgReplay(args, start);
50
+ }
51
+
52
+ function reportingDate(timezone) {
53
+ const offset = /^([+-])([01]\d|2[0-3]):([0-5]\d)$/.exec(timezone);
54
+ if (offset && offset[0] === timezone) {
55
+ const sign = offset[1] === '-' ? -1 : 1;
56
+ const adjustment = sign * (Number(offset[2]) * 60 + Number(offset[3])) * minuteMs;
57
+ return (time) => new Date(time + adjustment).toISOString().slice(0, 10);
58
+ }
59
+ return new Intl.DateTimeFormat('en-CA', { timeZone: timezone, dateStyle: 'short' }).format;
60
+ }
61
+
62
+ function generatePlgReplay(args, start) {
63
+ const {
64
+ 'sample-id': sampleId, 'item-id': itemId, 'cohort-file': cohortFile, 'run-id': runId, 'output-dir': outputDir,
65
+ 'experiment-id': experimentId, 'control-id': controlId, 'treatment-id': treatmentId,
66
+ } = args;
67
+ if (!cohortFile) throw new Error('Pass --cohort-file for the selected Demo sample.');
68
+ const { preset, sample, industry, experimentType } = resolveExperimentPreset({
69
+ industry: args.industry, experimentType: args['experiment-type'], sampleId, itemId,
70
+ });
71
+ const { exposureProperties, events } = preset;
72
+ const cohort = JSON.parse(readFileSync(cohortFile, 'utf8'));
73
+ if (!Array.isArray(cohort) || cohort.length < 2 || new Set(cohort).size !== cohort.length
74
+ || !cohort.every(id => isDemoAccountId(id, sampleId, sample.userCount))) {
75
+ throw new Error('The cohort must contain at least two unique synthetic account IDs for the selected PLG sample.');
76
+ }
77
+
78
+ const replayIdentity = [sampleId, itemId, runId, experimentId];
79
+ const ranked = cohort.map((id) => ({ id, rank: digest(['assignment', ...replayIdentity, id]).toString('hex') }))
80
+ .sort((left, right) => left.rank.localeCompare(right.rank) || left.id.localeCompare(right.id))
81
+ .map(({ id }) => id);
82
+ const split = Math.ceil(ranked.length / 2);
83
+ const exposure = [];
84
+ const outcomes = [];
85
+ const tags = { plg_sample_id: sampleId, item_id: itemId, demo_run_id: runId };
86
+ const event = (accountId, groupId, offset, eventName, properties) => ({
87
+ account_id: accountId,
88
+ time: new Date(start + offset).toISOString().slice(0, -1).replace('T', ' '),
89
+ event_name: eventName,
90
+ event_uuid: stableUuid(['event', ...replayIdentity, groupId, accountId, eventName]),
91
+ ...properties,
92
+ });
93
+ const arms = {};
94
+ for (const [name, groupId, assigned, isControl] of [
95
+ ['control', controlId, ranked.slice(0, split), true],
96
+ ['treatment', treatmentId, ranked.slice(split), false],
97
+ ]) {
98
+ const config = preset.arms[name];
99
+ const exposed = assigned.slice(0, config.exposureLimit ?? assigned.length);
100
+ const claims = events.couponClaim ? exposed.slice(0, config.couponClaims) : [];
101
+ const paid = (events.couponClaim && !isControl ? claims : exposed).slice(0, config.paidUsers);
102
+ exposed.forEach((id) => exposure.push(event(id, groupId, 0, events.exposure, {
103
+ experiment_id: experimentId, experiment_group_id: groupId, is_control_group: isControl,
104
+ })));
105
+ claims.forEach((id) => outcomes.push(event(id, groupId, outcomeDelayMs, events.couponClaim, tags)));
106
+ paid.forEach((id) => outcomes.push(event(id, groupId, outcomeDelayMs, events.payment, {
107
+ ...tags, order_id: stableUuid(['order', ...replayIdentity, groupId, id]), amount: config.price, currency: preset.currency,
108
+ })));
109
+ arms[name] = {
110
+ group_id: groupId, assigned_account_ids: assigned, exposed_account_ids: exposed,
111
+ coupon_claim_account_ids: claims, paid_account_ids: paid,
112
+ };
113
+ }
114
+ const rows = [...exposure, ...outcomes];
115
+ const properties = [
116
+ ...exposureProperties,
117
+ ['plg_sample_id', 'string'], ['item_id', 'string'], ['demo_run_id', 'string'],
118
+ ['order_id', 'string'], ['amount', 'number'], ['currency', 'string'],
119
+ ];
120
+ const receipt = {
121
+ version: 'ae-plg-demo-experiment-replay/v1', synthetic: true, phase: args.phase, run_id: runId,
122
+ sample_id: sampleId, item_id: itemId, industry, experiment_type: experimentType,
123
+ experiment_id: experimentId, timezone: args.timezone,
124
+ start: args.start, end: args.end, arms,
125
+ event_uuids: { exposure: exposure.map((row) => row.event_uuid), outcomes: outcomes.map((row) => row.event_uuid) },
126
+ };
127
+ const receiptName = 'plg-experiment-receipt.json';
128
+ writeReplay(outputDir, rows, properties, receiptName, receipt);
129
+ console.log(JSON.stringify({
130
+ synthetic: true, phase: args.phase, run_id: runId, sample_id: sampleId, item_id: itemId,
131
+ experiment_id: experimentId, receipt: receiptName, files: { replay: rows.length },
132
+ }, null, 2));
133
+ }
134
+
135
+ function digest(parts) {
136
+ return createHash('sha256').update(JSON.stringify(parts)).digest();
137
+ }
138
+
139
+ function stableUuid(parts) {
140
+ const bytes = digest(parts).subarray(0, 16);
141
+ bytes[6] = (bytes[6] & 0x0f) | 0x80;
142
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
143
+ const hex = bytes.toString('hex');
144
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
145
+ }
146
+
147
+ function writeReplay(outputDir, rows, properties, receiptName, receipt) {
148
+ mkdirSync(outputDir, { mode: 0o700 });
149
+ const source = rows.map((row) => JSON.stringify(row)).join('\n') + '\n';
150
+ writeFileSync(join(outputDir, 'replay.jsonl'), source);
151
+ const mapping = {
152
+ version: 'ae-data-integration-mapping/v1',
153
+ source: { sha256: createHash('sha256').update(source).digest('hex'), format: 'jsonl', data_set: '$' },
154
+ mode: 'track', confidence: 'high', account_id_field: 'account_id',
155
+ time: { field: 'time', format: 'auto', source_timezone: 'UTC' },
156
+ uuid_field: 'event_uuid',
157
+ zone_offset_value: 0,
158
+ event_name_field: 'event_name',
159
+ properties: properties.map(([column, type, target = column]) => ({ source: column, target, type })),
160
+ };
161
+ writeFileSync(join(outputDir, 'replay.mapping.json'), JSON.stringify(mapping, null, 2) + '\n');
162
+ writeFileSync(join(outputDir, receiptName), JSON.stringify(receipt, null, 2) + '\n');
163
+ }
164
+
165
+ try {
166
+ main();
167
+ } catch (error) {
168
+ console.error(error.message);
169
+ process.exitCode = 1;
170
+ }
@@ -0,0 +1,26 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ const catalog = JSON.parse(readFileSync(new URL('./experiment-preset.json', import.meta.url), 'utf8'));
4
+
5
+ export function isDemoAccountId(id, sampleId, userCount) {
6
+ if (typeof id !== 'string' || !id.startsWith(`${sampleId}-user-`)) return false;
7
+ const number = id.slice(sampleId.length + '-user-'.length);
8
+ return /^[1-9][0-9]{0,2}$/.test(number) && number === number.trim() && Number(number) <= userCount;
9
+ }
10
+
11
+ export function resolveExperimentPreset({ industry, experimentType, sampleId, itemId }) {
12
+ const matches = Object.entries(catalog.industries).filter(([id, { samples }]) =>
13
+ (industry === undefined || industry === id) && Object.hasOwn(samples, sampleId)
14
+ && samples[sampleId].itemId === itemId);
15
+ if (matches.length !== 1) {
16
+ throw new Error('The industry, sample ID and item ID must identify a supported Demo sample.');
17
+ }
18
+
19
+ const [industryId, { samples }] = matches[0];
20
+ const sample = samples[sampleId];
21
+ const experimentTypeId = experimentType ?? sample.experimentTypes[0];
22
+ if (!sample.experimentTypes.includes(experimentTypeId) || !Object.hasOwn(catalog.experimentTypes, experimentTypeId)) {
23
+ throw new Error(`Unsupported experiment type for ${industryId}/${sampleId}. Available: ${sample.experimentTypes.join(', ')}.`);
24
+ }
25
+ return { industry: industryId, experimentType: experimentTypeId, sample, preset: catalog.experimentTypes[experimentTypeId] };
26
+ }
@@ -0,0 +1,39 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+
5
+ const endpoint = process.argv[2];
6
+ const cwd = process.cwd();
7
+ const choices = {
8
+ 'choose-sample': { step: 'choose_sample', options: [{ value: 'star_island' }, { value: 'season_pass' }, { value: 'keep_sample' }] },
9
+ 'after-follow-up': { step: 'follow_up_ready', options: [{ value: 'experiment_plan' }, { value: 'change_sample' }] },
10
+ };
11
+ if (!(['done', 'stopped'].includes(endpoint) || Object.hasOwn(choices, endpoint))) {
12
+ throw new Error('Expected done, stopped, choose-sample, or after-follow-up.');
13
+ }
14
+ if (Object.hasOwn(choices, endpoint)) {
15
+ process.stdout.write(JSON.stringify({ ok: true, data: { interaction: choices[endpoint] } }) + '\n');
16
+ process.exit(0);
17
+ }
18
+
19
+ const directory = path.join(cwd, '.ae-onboarding');
20
+ await fs.mkdir(directory, { recursive: true, mode: 0o700 });
21
+ if (!(await fs.lstat(directory)).isDirectory()) throw new Error('Unsafe onboarding state directory.');
22
+ const target = path.join(directory, 'plg-journey.json');
23
+ const schema = 'ae-onboarding.state.v5';
24
+ const previous = await fs.lstat(target).catch(error => {
25
+ if (error.code !== 'ENOENT') throw error;
26
+ return null;
27
+ });
28
+ if (previous && (!previous.isFile() || previous.size > 8192)) throw new Error('Unsafe onboarding journey state.');
29
+ if (previous) {
30
+ const state = JSON.parse(await fs.readFile(target, 'utf8'));
31
+ if (state.schema === schema && state.endpoint === endpoint) process.exit(0);
32
+ }
33
+ const temp = path.join(directory, `.${randomUUID()}.tmp`);
34
+ try {
35
+ await fs.writeFile(temp, `${JSON.stringify({ schema, revision: Date.now(), endpoint })}\n`, { mode: 0o600, flag: 'wx' });
36
+ await fs.rename(temp, target);
37
+ } finally {
38
+ await fs.rm(temp, { force: true });
39
+ }
@@ -1,26 +0,0 @@
1
- import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
-
3
- // src/core/host-guidance.ts
4
- var AE_TRIAL_URL = "https://thinkingai.cn/request-demo";
5
- var AE_HOST_SETUP_COMMAND = "ae-cli config set-host <url>";
6
- function missingAeHostHint(additionalAction) {
7
- const actions = [
8
- `If your organization already uses AgenticEngine, ask your administrator for its AE URL, then run: ${AE_HOST_SETUP_COMMAND}.`,
9
- `If you do not have an AgenticEngine environment, request a trial: ${AE_TRIAL_URL}`
10
- ];
11
- if (additionalAction) actions.push(additionalAction);
12
- return actions.join(" ");
13
- }
14
- function missingAeHostGuidance() {
15
- return {
16
- configure_host: AE_HOST_SETUP_COMMAND,
17
- existing_customer: "Ask your AgenticEngine administrator for the AE environment URL.",
18
- request_trial_url: AE_TRIAL_URL
19
- };
20
- }
21
-
22
- export {
23
- AE_TRIAL_URL,
24
- missingAeHostHint,
25
- missingAeHostGuidance
26
- };