codebuff 1.0.225 → 1.0.226
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/background-process-manager.d.ts +10 -3
- package/dist/background-process-manager.js +110 -0
- package/dist/background-process-manager.js.map +1 -1
- package/dist/cli.js +8 -19
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +5 -5
- package/dist/client.js +9 -1
- package/dist/client.js.map +1 -1
- package/dist/code-map/tsconfig.tsbuildinfo +1 -1
- package/dist/common/actions.d.ts +134 -134
- package/dist/common/billing/balance-calculator.d.ts +0 -1
- package/dist/common/billing/balance-calculator.js +18 -11
- package/dist/common/billing/balance-calculator.js.map +1 -1
- package/dist/common/logger.d.ts +1 -0
- package/dist/common/logger.js +7 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/common/types/usage.d.ts +2 -2
- package/dist/common/util/constants.d.ts +1 -0
- package/dist/common/util/constants.js +7 -0
- package/dist/common/util/constants.js.map +1 -0
- package/dist/common/util/helpers.d.ts +1 -0
- package/dist/common/util/helpers.js +6 -0
- package/dist/common/util/helpers.js.map +1 -0
- package/dist/common/util/token-counter.d.ts +3 -0
- package/dist/common/util/token-counter.js +27 -0
- package/dist/common/util/token-counter.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +258 -258
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/json-config/dev-process-manager.js +10 -3
- package/dist/json-config/dev-process-manager.js.map +1 -1
- package/dist/project-files.js +1 -1
- package/dist/project-files.js.map +1 -1
- package/dist/utils/terminal.js +2 -2
- package/dist/utils/terminal.js.map +1 -1
- package/dist/utils/tool-renderers.js +18 -18
- package/dist/utils/tool-renderers.js.map +1 -1
- package/package.json +1 -1
- package/dist/common/advanced-analyzer.d.ts +0 -19
- package/dist/common/advanced-analyzer.js +0 -140
- package/dist/common/advanced-analyzer.js.map +0 -1
- package/dist/common/billing/check-auto-topup.d.ts +0 -12
- package/dist/common/billing/check-auto-topup.js +0 -50
- package/dist/common/billing/check-auto-topup.js.map +0 -1
- package/dist/common/billing/credit-check.d.ts +0 -8
- package/dist/common/billing/credit-check.js +0 -45
- package/dist/common/billing/credit-check.js.map +0 -1
- package/dist/common/billing/rollover-logic.d.ts +0 -13
- package/dist/common/billing/rollover-logic.js +0 -174
- package/dist/common/billing/rollover-logic.js.map +0 -1
- package/dist/common/billing/stripe-api.d.ts +0 -31
- package/dist/common/billing/stripe-api.js +0 -104
- package/dist/common/billing/stripe-api.js.map +0 -1
- package/dist/common/message-image-handling.d.ts +0 -41
- package/dist/common/message-image-handling.js +0 -57
- package/dist/common/message-image-handling.js.map +0 -1
- package/dist/common/types/billing.d.ts +0 -16
- package/dist/common/types/billing.js +0 -3
- package/dist/common/types/billing.js.map +0 -1
- package/dist/common/util/process-stream.d.ts +0 -8
- package/dist/common/util/process-stream.js +0 -102
- package/dist/common/util/process-stream.js.map +0 -1
- package/dist/common/util/referral-credits.d.ts +0 -1
- package/dist/common/util/referral-credits.js +0 -48
- package/dist/common/util/referral-credits.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check-auto-topup.js","sourceRoot":"","sources":["../../src/billing/check-auto-topup.ts"],"names":[],"mappings":";;AAgBA,sDAkDC;AAlED,2CAA6C;AAC7C,2CAAuC;AAEvC,yCAAiC;AAOjC;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CACzC,MAAc,EACd,gBAA+B;IAE/B,MAAM,UAAU,GAAG,EAAE,MAAM,EAAE,CAAA;IAE7B,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,OAAO;YACL,aAAa,EAAE,6DAA6D,aAAG,CAAC,mBAAmB,QAAQ;YAC3G,kBAAkB,EAAE,IAAI;SACzB,CAAA;IACH,CAAC;IAED,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,MAAM,qBAAY,CAAC,cAAc,CAAC,IAAI,CAAC;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,IAAI,EAAE,MAAM;SACb,CAAC,CAAA;QAEF,iCAAiC;QACjC,MAAM,kBAAkB,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CACjD,CAAC,EAAE,EAAE,EAAE,CACL,EAAE,CAAC,IAAI,EAAE,QAAQ;YACjB,EAAE,CAAC,IAAI,CAAC,SAAS;YACjB,IAAI,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,CACjE,CAAA;QAED,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,eAAM,CAAC,IAAI,CACT,EAAE,GAAG,UAAU,EAAE,EACjB,gDAAgD,CACjD,CAAA;YACD,OAAO;gBACL,aAAa,EACX,wGAAwG;gBAC1G,kBAAkB,EAAE,IAAI;aACzB,CAAA;QACH,CAAC;QAED,OAAO;YACL,aAAa,EAAE,IAAI;YACnB,kBAAkB;SACnB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,EAAE,KAAK,EAAE,EAAE,iCAAiC,CAAC,CAAA;QACzE,OAAO;YACL,aAAa,EAAE,yCAAyC;YACxD,kBAAkB,EAAE,IAAI;SACzB,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { CreditBalance } from './balance-calculator';
|
|
2
|
-
/**
|
|
3
|
-
* Gets the current detailed credit balance for a user.
|
|
4
|
-
* Returns a zero balance for anonymous users.
|
|
5
|
-
* @param userId The ID of the user, or undefined for anonymous.
|
|
6
|
-
* @returns A Promise resolving to the user's CreditBalance.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getCurrentBalanceDetails(userId: string | undefined): Promise<CreditBalance>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentBalanceDetails = getCurrentBalanceDetails;
|
|
4
|
-
const balance_calculator_1 = require("./balance-calculator");
|
|
5
|
-
const logger_1 = require("../util/logger");
|
|
6
|
-
/**
|
|
7
|
-
* Gets the current detailed credit balance for a user.
|
|
8
|
-
* Returns a zero balance for anonymous users.
|
|
9
|
-
* @param userId The ID of the user, or undefined for anonymous.
|
|
10
|
-
* @returns A Promise resolving to the user's CreditBalance.
|
|
11
|
-
*/
|
|
12
|
-
async function getCurrentBalanceDetails(userId) {
|
|
13
|
-
if (!userId) {
|
|
14
|
-
// Return zero/default balance for anonymous users
|
|
15
|
-
return {
|
|
16
|
-
totalRemaining: 0,
|
|
17
|
-
breakdown: {
|
|
18
|
-
free: 0,
|
|
19
|
-
referral: 0,
|
|
20
|
-
purchase: 0,
|
|
21
|
-
admin: 0,
|
|
22
|
-
rollover: 0,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
// Use the new balance calculation logic
|
|
28
|
-
return await (0, balance_calculator_1.calculateCurrentBalance)(userId);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
logger_1.logger.error({ userId, error }, 'Error fetching balance details');
|
|
32
|
-
// Return a zero balance on error
|
|
33
|
-
return {
|
|
34
|
-
totalRemaining: 0,
|
|
35
|
-
breakdown: {
|
|
36
|
-
free: 0,
|
|
37
|
-
referral: 0,
|
|
38
|
-
purchase: 0,
|
|
39
|
-
admin: 0,
|
|
40
|
-
rollover: 0,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=credit-check.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credit-check.js","sourceRoot":"","sources":["../../src/billing/credit-check.ts"],"names":[],"mappings":";;AASA,4DAkCC;AA3CD,6DAA6E;AAC7E,2CAAuC;AAEvC;;;;;GAKG;AACI,KAAK,UAAU,wBAAwB,CAC5C,MAA0B;IAE1B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,kDAAkD;QAClD,OAAO;YACL,cAAc,EAAE,CAAC;YACjB,SAAS,EAAE;gBACT,IAAI,EAAE,CAAC;gBACP,QAAQ,EAAE,CAAC;gBACX,QAAQ,EAAE,CAAC;gBACX,KAAK,EAAE,CAAC;gBACR,QAAQ,EAAE,CAAC;aACZ;SACF,CAAA;IACH,CAAC;IAED,IAAI,CAAC;QACH,wCAAwC;QACxC,OAAO,MAAM,IAAA,4CAAuB,EAAC,MAAM,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,gCAAgC,CAAC,CAAA;QACjE,iCAAiC;QACjC,OAAO;YACL,cAAc,EAAE,CAAC;YACjB,SAAS,EAAE;gBACT,IAAI,EAAE,CAAC;gBACP,QAAQ,EAAE,CAAC;gBACX,QAAQ,EAAE,CAAC;gBACX,KAAK,EAAE,CAAC;gBACR,QAAQ,EAAE,CAAC;aACZ;SACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the rollover amount for a user at the end of their billing cycle
|
|
3
|
-
* and applies the necessary database updates (creates rollover grant, resets usage, updates reset date).
|
|
4
|
-
*
|
|
5
|
-
* NOTE: This function performs database writes and should be called within a transaction
|
|
6
|
-
* if invoked alongside other database operations. It also depends on the `credit_grants`
|
|
7
|
-
* table and the modified `user` table schema being in place.
|
|
8
|
-
*
|
|
9
|
-
* @param userId The ID of the user whose cycle is ending.
|
|
10
|
-
* @param cycleEndDate The exact date and time the billing cycle ended.
|
|
11
|
-
* @returns A Promise resolving when the process is complete.
|
|
12
|
-
*/
|
|
13
|
-
export declare function calculateAndApplyRollover(userId: string, cycleEndDate: Date): Promise<void>;
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.calculateAndApplyRollover = calculateAndApplyRollover;
|
|
30
|
-
const db_1 = __importDefault(require("../db"));
|
|
31
|
-
const schema = __importStar(require("../db/schema"));
|
|
32
|
-
const drizzle_orm_1 = require("drizzle-orm");
|
|
33
|
-
const balance_calculator_1 = require("./balance-calculator");
|
|
34
|
-
const logger_1 = require("../util/logger");
|
|
35
|
-
const dates_1 = require("../util/dates"); // Assuming this utility exists/is created
|
|
36
|
-
// Define which grant types contribute to rollover
|
|
37
|
-
const ROLLOVER_GRANT_TYPES = ['purchase', 'rollover'];
|
|
38
|
-
/**
|
|
39
|
-
* Calculates the rollover amount for a user at the end of their billing cycle
|
|
40
|
-
* and applies the necessary database updates (creates rollover grant, resets usage, updates reset date).
|
|
41
|
-
*
|
|
42
|
-
* NOTE: This function performs database writes and should be called within a transaction
|
|
43
|
-
* if invoked alongside other database operations. It also depends on the `credit_grants`
|
|
44
|
-
* table and the modified `user` table schema being in place.
|
|
45
|
-
*
|
|
46
|
-
* @param userId The ID of the user whose cycle is ending.
|
|
47
|
-
* @param cycleEndDate The exact date and time the billing cycle ended.
|
|
48
|
-
* @returns A Promise resolving when the process is complete.
|
|
49
|
-
*/
|
|
50
|
-
async function calculateAndApplyRollover(userId, cycleEndDate) {
|
|
51
|
-
logger_1.logger.info({ userId, cycleEndDate }, 'Starting end-of-cycle rollover process');
|
|
52
|
-
try {
|
|
53
|
-
// 1. Fetch the user's usage for the cycle that just ended
|
|
54
|
-
// We need the user record to get the usage *before* resetting it.
|
|
55
|
-
const user = await db_1.default.query.user.findFirst({
|
|
56
|
-
where: (0, drizzle_orm_1.eq)(schema.user.id, userId),
|
|
57
|
-
columns: { usage: true, next_quota_reset: true }, // Also get current reset date
|
|
58
|
-
});
|
|
59
|
-
if (!user) {
|
|
60
|
-
logger_1.logger.error({ userId }, 'User not found during rollover calculation.');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
// Ensure we don't run rollover multiple times for the same cycle
|
|
64
|
-
if (user.next_quota_reset && user.next_quota_reset > cycleEndDate) {
|
|
65
|
-
logger_1.logger.warn({ userId, cycleEndDate, nextReset: user.next_quota_reset }, 'Rollover attempted for a cycle that has not yet ended or already processed. Skipping.');
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const endedCycleUsage = user.usage;
|
|
69
|
-
// Calculate the start date of the ended cycle (approximate)
|
|
70
|
-
const cycleStartDate = new Date(cycleEndDate);
|
|
71
|
-
cycleStartDate.setMonth(cycleStartDate.getMonth() - 1); // Approximation
|
|
72
|
-
// 2. Fetch all grants that were active *during* the ended cycle
|
|
73
|
-
// Active during cycle: created_at < cycleEndDate AND (expires_at IS NULL OR expires_at > cycleStartDate)
|
|
74
|
-
const grantsActiveDuringCycle = await db_1.default
|
|
75
|
-
.select()
|
|
76
|
-
.from(schema.creditGrants)
|
|
77
|
-
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(schema.creditGrants.user_id, userId), (0, drizzle_orm_1.lte)(schema.creditGrants.created_at, cycleEndDate), // Created before or exactly at cycle end
|
|
78
|
-
(0, drizzle_orm_1.or)((0, drizzle_orm_1.isNull)(schema.creditGrants.expires_at), // Never expires
|
|
79
|
-
(0, drizzle_orm_1.gt)(schema.creditGrants.expires_at, cycleStartDate) // Expired after cycle start
|
|
80
|
-
)))
|
|
81
|
-
// 3. Order grants by priority ASC, then created_at ASC
|
|
82
|
-
.orderBy((0, drizzle_orm_1.asc)(schema.creditGrants.priority), (0, drizzle_orm_1.asc)(schema.creditGrants.created_at));
|
|
83
|
-
// 4. Initialize rollover amount
|
|
84
|
-
let rolloverAmount = 0;
|
|
85
|
-
// 5. Initialize usage to account for from the ended cycle
|
|
86
|
-
let usageToAccountFor = endedCycleUsage;
|
|
87
|
-
logger_1.logger.debug({ userId, endedCycleUsage, grantsCount: grantsActiveDuringCycle.length }, 'Simulating consumption for ended cycle');
|
|
88
|
-
// 6. Simulate Cycle Consumption
|
|
89
|
-
for (const grant of grantsActiveDuringCycle) {
|
|
90
|
-
const consumedFromThisGrant = Math.min(grant.amount, usageToAccountFor);
|
|
91
|
-
const remainingInThisGrant = grant.amount - consumedFromThisGrant;
|
|
92
|
-
usageToAccountFor -= consumedFromThisGrant;
|
|
93
|
-
logger_1.logger.trace({
|
|
94
|
-
userId,
|
|
95
|
-
grantId: grant.operation_id,
|
|
96
|
-
grantType: grant.type,
|
|
97
|
-
grantAmount: grant.amount,
|
|
98
|
-
consumed: consumedFromThisGrant,
|
|
99
|
-
remainingInGrant: remainingInThisGrant,
|
|
100
|
-
usageLeftToAccount: usageToAccountFor,
|
|
101
|
-
}, 'Processing grant during rollover simulation');
|
|
102
|
-
// 7. Check for Rollover Contribution
|
|
103
|
-
if (remainingInThisGrant > 0 &&
|
|
104
|
-
ROLLOVER_GRANT_TYPES.includes(grant.type)) {
|
|
105
|
-
rolloverAmount += remainingInThisGrant;
|
|
106
|
-
logger_1.logger.trace({
|
|
107
|
-
userId,
|
|
108
|
-
grantId: grant.operation_id,
|
|
109
|
-
addedToRollover: remainingInThisGrant,
|
|
110
|
-
newTotalRollover: rolloverAmount,
|
|
111
|
-
}, 'Grant contributed to rollover amount');
|
|
112
|
-
}
|
|
113
|
-
if (usageToAccountFor <= 0) {
|
|
114
|
-
// If usage is covered, check remaining grants for rollover contributions
|
|
115
|
-
const remainingGrants = grantsActiveDuringCycle.slice(grantsActiveDuringCycle.indexOf(grant) + 1);
|
|
116
|
-
for (const remainingGrant of remainingGrants) {
|
|
117
|
-
if (ROLLOVER_GRANT_TYPES.includes(remainingGrant.type)) {
|
|
118
|
-
rolloverAmount += remainingGrant.amount;
|
|
119
|
-
logger_1.logger.trace({
|
|
120
|
-
userId,
|
|
121
|
-
grantId: remainingGrant.operation_id,
|
|
122
|
-
addedToRollover: remainingGrant.amount,
|
|
123
|
-
newTotalRollover: rolloverAmount,
|
|
124
|
-
}, 'Untouched grant contributed to rollover amount');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
break; // All usage accounted for
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
logger_1.logger.info({ userId, endedCycleUsage, calculatedRollover: rolloverAmount }, 'Rollover calculation complete');
|
|
131
|
-
// 8. Database Updates (Perform as a transaction)
|
|
132
|
-
await db_1.default.transaction(async (tx) => {
|
|
133
|
-
// Insert new 'rollover' grant if amount > 0
|
|
134
|
-
if (rolloverAmount > 0) {
|
|
135
|
-
const rolloverGrantId = `rollover-${userId}-${cycleEndDate.toISOString()}`;
|
|
136
|
-
await tx
|
|
137
|
-
.insert(schema.creditGrants)
|
|
138
|
-
.values({
|
|
139
|
-
operation_id: rolloverGrantId,
|
|
140
|
-
user_id: userId,
|
|
141
|
-
amount: rolloverAmount,
|
|
142
|
-
amount_remaining: rolloverAmount, // Initialize amount_remaining to the full amount
|
|
143
|
-
type: 'rollover', // Use string literal directly
|
|
144
|
-
priority: balance_calculator_1.GRANT_PRIORITIES.rollover, // Use defined priority
|
|
145
|
-
expires_at: null, // Rollover credits don't expire
|
|
146
|
-
description: `Rollover from cycle ending ${cycleEndDate.toLocaleDateString()}`,
|
|
147
|
-
// stripe_grant_id is NULL for local grants
|
|
148
|
-
})
|
|
149
|
-
.onConflictDoNothing(); // Avoid duplicate rollovers if run concurrently
|
|
150
|
-
logger_1.logger.debug({ userId, rolloverAmount }, 'Inserted rollover grant');
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
logger_1.logger.debug({ userId }, 'No rollover amount to grant.');
|
|
154
|
-
}
|
|
155
|
-
// Update the user: reset usage and set next reset date
|
|
156
|
-
const nextResetDate = (0, dates_1.getNextQuotaReset)(cycleEndDate); // Calculate the next reset date based on the cycle end
|
|
157
|
-
await tx
|
|
158
|
-
.update(schema.user)
|
|
159
|
-
.set({
|
|
160
|
-
usage: 0,
|
|
161
|
-
next_quota_reset: nextResetDate,
|
|
162
|
-
})
|
|
163
|
-
.where((0, drizzle_orm_1.eq)(schema.user.id, userId));
|
|
164
|
-
logger_1.logger.info({ userId, nextResetDate: nextResetDate.toISOString() }, 'User usage reset and next reset date updated');
|
|
165
|
-
});
|
|
166
|
-
logger_1.logger.info({ userId }, 'Rollover process completed successfully.');
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
logger_1.logger.error({ userId, cycleEndDate, error }, 'Error during rollover process');
|
|
170
|
-
// Depending on trigger mechanism, might need error handling/retry logic here
|
|
171
|
-
throw error; // Re-throw to indicate failure if called from a job
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
//# sourceMappingURL=rollover-logic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rollover-logic.js","sourceRoot":"","sources":["../../src/billing/rollover-logic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,8DAsLC;AA7MD,+CAAsB;AACtB,qDAAsC;AACtC,6CAAoE;AACpE,6DAAuD;AACvD,2CAAuC;AACvC,yCAAiD,CAAC,0CAA0C;AAG5F,kDAAkD;AAClD,MAAM,oBAAoB,GAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAElE;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,yBAAyB,CAC7C,MAAc,EACd,YAAkB;IAElB,eAAM,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,YAAY,EAAE,EACxB,wCAAwC,CACzC,CAAA;IAED,IAAI,CAAC;QACH,0DAA0D;QAC1D,kEAAkE;QAClE,MAAM,IAAI,GAAG,MAAM,YAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YACzC,KAAK,EAAE,IAAA,gBAAE,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC;YACjC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,8BAA8B;SACjF,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,eAAM,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE,6CAA6C,CAAC,CAAA;YACvE,OAAM;QACR,CAAC;QAED,iEAAiE;QACjE,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,GAAG,YAAY,EAAE,CAAC;YAClE,eAAM,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAC1D,uFAAuF,CACxF,CA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D;YAC7G,MAAM,EAAE;iBACL,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;iBACnB,GAAG,CAAC;gBACH,KAAK,EAAE,CAAC;gBACR,gBAAgB,EAAE,aAAa;aAChC,CAAC;iBACD,KAAK,CAAC,IAAA,gBAAE,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAA;YAEpC,eAAM,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,CAAC,WAAW,EAAE,EAAE,EACtD,8CAA8C,CAC/C,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,eAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,0CAA0C,CAAC,CAAA;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CACV,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,EAC/B,+BAA+B,CAChC,CAAA;QACD,6EAA6E;QAC7E,MAAM,KAAK,CAAA,CAAC,oDAAoD;IAClE,CAAC;AACH,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { CreditType } from './balance-calculator';
|
|
2
|
-
import Stripe from 'stripe';
|
|
3
|
-
export declare const stripeApi: {
|
|
4
|
-
credits: {
|
|
5
|
-
/**
|
|
6
|
-
* Creates a customer balance transaction in Stripe to grant credits.
|
|
7
|
-
* NOTE: Database insertion for a local 'creditGrant' record is commented out
|
|
8
|
-
* as the 'creditGrant' table doesn't exist in the current schema.
|
|
9
|
-
*/
|
|
10
|
-
create({ userId, amount, type, expiresAt, description, metadata }: {
|
|
11
|
-
userId: string;
|
|
12
|
-
amount: number;
|
|
13
|
-
type: CreditType;
|
|
14
|
-
expiresAt?: Date;
|
|
15
|
-
description?: string;
|
|
16
|
-
metadata?: Record<string, string | number | null>;
|
|
17
|
-
}): Promise<Stripe.CustomerBalanceTransaction>;
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves the customer's cash balance from Stripe.
|
|
20
|
-
* Note: This is the overall cash balance, typically negative if credits have been granted.
|
|
21
|
-
* It does NOT represent the sum of specific "credit grants".
|
|
22
|
-
*/
|
|
23
|
-
getBalance(userId: string): Promise<number>;
|
|
24
|
-
};
|
|
25
|
-
usage: {
|
|
26
|
-
/**
|
|
27
|
-
* Reports usage to a Stripe meter.
|
|
28
|
-
*/
|
|
29
|
-
report(userId: string, amount: number, metadata?: Record<string, any>): Promise<Stripe.Response<Stripe.Billing.MeterEvent>>;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.stripeApi = void 0;
|
|
30
|
-
const db_1 = __importDefault(require("../db"));
|
|
31
|
-
const schema = __importStar(require("../db/schema"));
|
|
32
|
-
const drizzle_orm_1 = require("drizzle-orm");
|
|
33
|
-
const stripe_1 = require("../util/stripe");
|
|
34
|
-
const balance_calculator_1 = require("./balance-calculator");
|
|
35
|
-
// Helper to get Stripe Customer ID
|
|
36
|
-
async function getCustomerId(userId) {
|
|
37
|
-
const user = await db_1.default.query.user.findFirst({
|
|
38
|
-
where: (0, drizzle_orm_1.eq)(schema.user.id, userId),
|
|
39
|
-
columns: { stripe_customer_id: true }
|
|
40
|
-
});
|
|
41
|
-
if (!user?.stripe_customer_id) {
|
|
42
|
-
throw new Error(`Stripe customer ID not found for user ${userId}`);
|
|
43
|
-
}
|
|
44
|
-
return user.stripe_customer_id;
|
|
45
|
-
}
|
|
46
|
-
exports.stripeApi = {
|
|
47
|
-
credits: {
|
|
48
|
-
/**
|
|
49
|
-
* Creates a customer balance transaction in Stripe to grant credits.
|
|
50
|
-
* NOTE: Database insertion for a local 'creditGrant' record is commented out
|
|
51
|
-
* as the 'creditGrant' table doesn't exist in the current schema.
|
|
52
|
-
*/
|
|
53
|
-
async create({ userId, amount, type, expiresAt, description, metadata = {} }) {
|
|
54
|
-
const customerId = await getCustomerId(userId);
|
|
55
|
-
const priority = balance_calculator_1.CREDIT_PRIORITIES[type];
|
|
56
|
-
const amountInCents = -Math.abs(amount);
|
|
57
|
-
const transaction = await stripe_1.stripeServer.customers.createBalanceTransaction(customerId, {
|
|
58
|
-
amount: amountInCents,
|
|
59
|
-
currency: 'usd',
|
|
60
|
-
description: description ?? `${type} credits granted`,
|
|
61
|
-
metadata: {
|
|
62
|
-
...metadata,
|
|
63
|
-
type: type,
|
|
64
|
-
priority: priority.toString(),
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return transaction;
|
|
68
|
-
},
|
|
69
|
-
/**
|
|
70
|
-
* Retrieves the customer's cash balance from Stripe.
|
|
71
|
-
* Note: This is the overall cash balance, typically negative if credits have been granted.
|
|
72
|
-
* It does NOT represent the sum of specific "credit grants".
|
|
73
|
-
*/
|
|
74
|
-
async getBalance(userId) {
|
|
75
|
-
const customerId = await getCustomerId(userId);
|
|
76
|
-
const customer = await stripe_1.stripeServer.customers.retrieve(customerId);
|
|
77
|
-
if (customer.deleted) {
|
|
78
|
-
return 0;
|
|
79
|
-
}
|
|
80
|
-
return customer.balance ?? 0;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
usage: {
|
|
84
|
-
/**
|
|
85
|
-
* Reports usage to a Stripe meter.
|
|
86
|
-
*/
|
|
87
|
-
async report(userId, amount, metadata = {}) {
|
|
88
|
-
const customerId = await getCustomerId(userId);
|
|
89
|
-
const eventName = 'codebuff_credits_used';
|
|
90
|
-
return stripe_1.stripeServer.billing.meterEvents.create({
|
|
91
|
-
event_name: eventName,
|
|
92
|
-
timestamp: Math.floor(Date.now() / 1000),
|
|
93
|
-
payload: {
|
|
94
|
-
stripe_customer_id: customerId,
|
|
95
|
-
value: amount.toString(),
|
|
96
|
-
...metadata
|
|
97
|
-
}
|
|
98
|
-
}).catch((err) => {
|
|
99
|
-
throw err;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
//# sourceMappingURL=stripe-api.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-api.js","sourceRoot":"","sources":["../../src/billing/stripe-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAsB;AACtB,qDAAsC;AACtC,6CAAgC;AAChC,2CAA6C;AAC7C,6DAAoE;AAGpE,mCAAmC;AACnC,KAAK,UAAU,aAAa,CAAC,MAAc;IACvC,MAAM,IAAI,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,QAAQ,GAAG,MAAM,qBAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAEnE,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,CAAC;YACb,CAAC;YAED,OAAO,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;QACjC,CAAC;KACF;IACD,KAAK,EAAE;QACL;;WAEG;QACH,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,MAAc,EAAE,WAAgC,EAAE;YAC7E,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,CAAA;YAC9C,MAAM,SAAS,GAAG,uBAAuB,CAAC;YAE1C,OAAO,qBAAY,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC;gBAC7C,UAAU,EAAE,SAAS;gBACrB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;gBACxC,OAAO,EAAE;oBACP,kBAAkB,EAAE,UAAU;oBAC9B,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE;oBACxB,GAAG,QAAQ;iBACZ;aACF,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;gBACpB,MAAM,GAAG,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;KACF;CACF,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Message } from './actions';
|
|
2
|
-
/**
|
|
3
|
-
* Contexts where message processing may occur
|
|
4
|
-
*/
|
|
5
|
-
export declare enum ProcessingContext {
|
|
6
|
-
ModelCall = "model-call",
|
|
7
|
-
FileCache = "file-cache",
|
|
8
|
-
WarmCache = "warm-cache"
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Interface for provider-specific image handling
|
|
12
|
-
*/
|
|
13
|
-
export interface IImageHandler {
|
|
14
|
-
/**
|
|
15
|
-
* Returns whether images should be passed along in the given context
|
|
16
|
-
*/
|
|
17
|
-
supportsImages(context: ProcessingContext): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Transform a message by either stripping, replacing, or modifying image blocks
|
|
20
|
-
*/
|
|
21
|
-
transformMessage(message: Message, context: ProcessingContext): Message;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Base handler that removes all images unless explicitly allowed
|
|
25
|
-
*/
|
|
26
|
-
export declare class DefaultImageHandler implements IImageHandler {
|
|
27
|
-
supportsImages(context: ProcessingContext): boolean;
|
|
28
|
-
transformMessage(message: Message, context: ProcessingContext): Message;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Register a new image handler for a provider
|
|
32
|
-
*/
|
|
33
|
-
export declare function registerImageHandler(provider: string, handler: IImageHandler): void;
|
|
34
|
-
/**
|
|
35
|
-
* Transform a message for a specific provider and context
|
|
36
|
-
*/
|
|
37
|
-
export declare function transformMessageForProvider(message: Message, provider: string, context: ProcessingContext): Message;
|
|
38
|
-
/**
|
|
39
|
-
* Transform an array of messages for a specific provider and context
|
|
40
|
-
*/
|
|
41
|
-
export declare function transformMessagesForProvider(messages: Message[], provider: string, context: ProcessingContext): Message[];
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultImageHandler = exports.ProcessingContext = void 0;
|
|
4
|
-
exports.registerImageHandler = registerImageHandler;
|
|
5
|
-
exports.transformMessageForProvider = transformMessageForProvider;
|
|
6
|
-
exports.transformMessagesForProvider = transformMessagesForProvider;
|
|
7
|
-
/**
|
|
8
|
-
* Contexts where message processing may occur
|
|
9
|
-
*/
|
|
10
|
-
var ProcessingContext;
|
|
11
|
-
(function (ProcessingContext) {
|
|
12
|
-
ProcessingContext["ModelCall"] = "model-call";
|
|
13
|
-
ProcessingContext["FileCache"] = "file-cache";
|
|
14
|
-
ProcessingContext["WarmCache"] = "warm-cache";
|
|
15
|
-
})(ProcessingContext || (exports.ProcessingContext = ProcessingContext = {}));
|
|
16
|
-
/**
|
|
17
|
-
* Base handler that removes all images unless explicitly allowed
|
|
18
|
-
*/
|
|
19
|
-
class DefaultImageHandler {
|
|
20
|
-
supportsImages(context) {
|
|
21
|
-
return context === ProcessingContext.FileCache;
|
|
22
|
-
}
|
|
23
|
-
transformMessage(message, context) {
|
|
24
|
-
if (!this.supportsImages(context)) {
|
|
25
|
-
const transformed = Array.isArray(message.content)
|
|
26
|
-
? message.content.filter(block => typeof block === 'string' ? true : block.type !== 'image')
|
|
27
|
-
: message.content;
|
|
28
|
-
return { ...message, content: transformed };
|
|
29
|
-
}
|
|
30
|
-
return message;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.DefaultImageHandler = DefaultImageHandler;
|
|
34
|
-
/**
|
|
35
|
-
* Registry mapping provider names to their image handlers
|
|
36
|
-
*/
|
|
37
|
-
const imageHandlerRegistry = {};
|
|
38
|
-
/**
|
|
39
|
-
* Register a new image handler for a provider
|
|
40
|
-
*/
|
|
41
|
-
function registerImageHandler(provider, handler) {
|
|
42
|
-
imageHandlerRegistry[provider] = handler;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Transform a message for a specific provider and context
|
|
46
|
-
*/
|
|
47
|
-
function transformMessageForProvider(message, provider, context) {
|
|
48
|
-
const handler = imageHandlerRegistry[provider] || new DefaultImageHandler();
|
|
49
|
-
return handler.transformMessage(message, context);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Transform an array of messages for a specific provider and context
|
|
53
|
-
*/
|
|
54
|
-
function transformMessagesForProvider(messages, provider, context) {
|
|
55
|
-
return messages.map(message => transformMessageForProvider(message, provider, context));
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=message-image-handling.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-image-handling.js","sourceRoot":"","sources":["../src/message-image-handling.ts"],"names":[],"mappings":";;;AAuDA,oDAEC;AAKD,kEA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AE,OAAO,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,QAAmB,EACnB,QAAgB,EAChB,OAA0B;IAE1B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type GrantType = 'free' | 'referral' | 'purchase' | 'admin';
|
|
2
|
-
export interface CreditBalance {
|
|
3
|
-
totalRemaining: number;
|
|
4
|
-
totalDebt: number;
|
|
5
|
-
netBalance: number;
|
|
6
|
-
breakdown: Partial<Record<GrantType, number>>;
|
|
7
|
-
principals: Partial<Record<GrantType, number>>;
|
|
8
|
-
}
|
|
9
|
-
export interface CreditUsageAndBalance {
|
|
10
|
-
usageThisCycle: number;
|
|
11
|
-
balance: CreditBalance;
|
|
12
|
-
}
|
|
13
|
-
export interface CreditConsumptionResult {
|
|
14
|
-
consumed: number;
|
|
15
|
-
fromPurchased: number;
|
|
16
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/types/billing.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function processStreamWithTags<T extends string>(stream: AsyncGenerator<T> | ReadableStream<T>, tags: {
|
|
2
|
-
[tagName: string]: {
|
|
3
|
-
attributeNames: string[];
|
|
4
|
-
onTagStart: (attributes: Record<string, string>) => void;
|
|
5
|
-
onTagEnd: (content: string, attributes: Record<string, string>) => boolean;
|
|
6
|
-
};
|
|
7
|
-
}): AsyncGenerator<string, void, unknown>;
|
|
8
|
-
export declare function parseAttributes(attributesString: string, attributeNames: string[]): Record<string, string>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processStreamWithTags = processStreamWithTags;
|
|
4
|
-
exports.parseAttributes = parseAttributes;
|
|
5
|
-
async function* processStreamWithTags(stream, tags) {
|
|
6
|
-
let buffer = '';
|
|
7
|
-
let insideTag = null;
|
|
8
|
-
let currentAttributes = {};
|
|
9
|
-
let streamCompleted = false;
|
|
10
|
-
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
-
const tagNames = Object.keys(tags);
|
|
12
|
-
const openTagRegex = new RegExp(`<(${tagNames.map(escapeRegExp).join('|')})\\s*([^>]*)>`);
|
|
13
|
-
const closeTagRegex = new RegExp(`</(${tagNames.map(escapeRegExp).join('|')})>`);
|
|
14
|
-
function* parseBuffer(chunk) {
|
|
15
|
-
const isEOF = chunk === undefined;
|
|
16
|
-
if (chunk) {
|
|
17
|
-
yield chunk;
|
|
18
|
-
}
|
|
19
|
-
let didParse = true;
|
|
20
|
-
while (!streamCompleted && didParse) {
|
|
21
|
-
didParse = false;
|
|
22
|
-
if (insideTag === null) {
|
|
23
|
-
// Outside a tag: try to find the next opening tag
|
|
24
|
-
const openMatch = buffer.match(openTagRegex);
|
|
25
|
-
if (openMatch && openMatch.index !== undefined) {
|
|
26
|
-
const [fullMatch, openTag, attributesString] = openMatch;
|
|
27
|
-
const beforeTag = buffer.slice(0, openMatch.index);
|
|
28
|
-
const afterMatchIndex = openMatch.index + fullMatch.length;
|
|
29
|
-
// Move buffer forward
|
|
30
|
-
buffer = buffer.slice(afterMatchIndex);
|
|
31
|
-
// We are now inside this tag
|
|
32
|
-
insideTag = openTag;
|
|
33
|
-
currentAttributes = parseAttributes(attributesString, tags[openTag].attributeNames);
|
|
34
|
-
// Call onTagStart
|
|
35
|
-
tags[openTag].onTagStart(currentAttributes);
|
|
36
|
-
didParse = true;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// No opening tag found. If it's EOF, yield remaining text.
|
|
40
|
-
if (isEOF && buffer.length > 0) {
|
|
41
|
-
buffer = '';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
// Inside a tag: try to find the closing tag
|
|
47
|
-
const closeMatch = buffer.match(closeTagRegex);
|
|
48
|
-
if (closeMatch && closeMatch.index !== undefined) {
|
|
49
|
-
const [fullMatch, closeTag] = closeMatch;
|
|
50
|
-
const content = buffer.slice(0, closeMatch.index);
|
|
51
|
-
// Move buffer forward
|
|
52
|
-
buffer = buffer.slice(closeMatch.index + fullMatch.length);
|
|
53
|
-
// Close the tag
|
|
54
|
-
const complete = tags[insideTag].onTagEnd(content, currentAttributes);
|
|
55
|
-
insideTag = null;
|
|
56
|
-
currentAttributes = {};
|
|
57
|
-
if (complete) {
|
|
58
|
-
// If onTagEnd signals completion, set streamCompleted and return
|
|
59
|
-
streamCompleted = true;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
didParse = true;
|
|
63
|
-
}
|
|
64
|
-
else if (isEOF) {
|
|
65
|
-
// We reached EOF without finding a closing tag
|
|
66
|
-
// Treat remaining buffer as content and close the tag
|
|
67
|
-
if (buffer.length > 0) {
|
|
68
|
-
const complete = tags[insideTag].onTagEnd(buffer, currentAttributes);
|
|
69
|
-
yield '</' + insideTag + '>';
|
|
70
|
-
buffer = '';
|
|
71
|
-
insideTag = null;
|
|
72
|
-
currentAttributes = {};
|
|
73
|
-
if (complete) {
|
|
74
|
-
streamCompleted = true;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
for await (const chunk of stream) {
|
|
83
|
-
if (streamCompleted)
|
|
84
|
-
continue;
|
|
85
|
-
buffer += chunk;
|
|
86
|
-
yield* parseBuffer(chunk);
|
|
87
|
-
}
|
|
88
|
-
if (!streamCompleted) {
|
|
89
|
-
// After the stream ends, try parsing one last time in case there's leftover text
|
|
90
|
-
yield* parseBuffer(undefined);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function parseAttributes(attributesString, attributeNames) {
|
|
94
|
-
const attributes = {};
|
|
95
|
-
const regex = new RegExp(`(${attributeNames.join('|')})="([^"]*)"`, 'g');
|
|
96
|
-
let match;
|
|
97
|
-
while ((match = regex.exec(attributesString)) !== null) {
|
|
98
|
-
attributes[match[1]] = match[2];
|
|
99
|
-
}
|
|
100
|
-
return attributes;
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=process-stream.js.map
|