Skip to content

Feat/data hub#59

Merged
thedevyashsaini merged 2 commits into
mainfrom
feat/data-hub
May 31, 2026
Merged

Feat/data hub#59
thedevyashsaini merged 2 commits into
mainfrom
feat/data-hub

Conversation

@thedevyashsaini

Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: Devyash Saini <dysaini2004@gmail.com>
@thedevyashsaini thedevyashsaini merged commit 1331225 into main May 31, 2026
2 of 3 checks passed
@greptile-apps

greptile-apps Bot commented May 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR renames the sdkEvent analytics query builder to basicUsage across the @scrawn/analytics package, aligning the event type sent to the gRPC backend from "SDK_CALL" to "BASIC_USAGE". The example for the AI SDK wrapper is also extended to demonstrate direct use of biller.trackAI via the raw ai.streamText onFinish callback.

  • SdkEventBuilder/sdkEvent is deleted and replaced by BasicUsageBuilder/basicUsage in EventQueries, analytics.ts, fields.ts, and the codegen script — all references are consistent.
  • The example analytics-usage.ts is updated to use the new basicUsage builder, and the neq import is cleaned up since it was no longer referenced.
  • A second streamText call is added to ai-sdk-wrapper-usage.ts showing raw SDK usage with manual billing via biller.trackAI.

Confidence Score: 3/5

The rename is internally consistent, but the changeset labels a breaking public API removal as a patch release, which would cause silent runtime failures for existing consumers without a proper version signal.

The removal of the sdkEvent property from the exported EventQueries interface, without a corresponding major (or at minimum minor) version bump in the changeset, means downstream users who rely on analytics.query.sdkEvent will break silently after upgrading. The rest of the rename is internally consistent, and the example unused-variable issue is minor.

.changeset/eager-bottles-train.md needs the bump type corrected before this ships; examples/ai-sdk-wrapper-usage.ts has an unused result variable worth addressing.

Important Files Changed

Filename Overview
.changeset/eager-bottles-train.md Changeset labels this as a "patch" release, but removing the public sdkEvent property from the exported EventQueries interface is a breaking API change that would break existing consumers.
packages/analytics/src/analytics.ts Replaces SdkEventBuilder/sdkEvent with BasicUsageBuilder/basicUsage in EventQueries interface and Analytics constructor — a public API rename.
packages/analytics/src/query/basicUsage.ts New file: BasicUsageBuilder extending BaseEventBuilder, registered with event type "BASIC_USAGE" (previously "SDK_CALL").
packages/analytics/src/query/sdkEvent.ts Deleted: SdkEventBuilder removed as part of the rename to BasicUsageBuilder.
packages/analytics/src/query/fields.ts Auto-generated file: sdkEventFields renamed to basicUsageFields with identical field set.
examples/ai-sdk-wrapper-usage.ts Adds a second streamText call via raw ai SDK with biller.trackAI in onFinish; result1 is assigned but never consumed or logged.
examples/analytics-usage.ts Example updated from sdkEvent to basicUsage throughout; neq import removed (was unused after refactor).
packages/analytics/scripts/gen-fields.ts Codegen script updated to produce basicUsage fields instead of sdkCall; logic is consistent with the rename.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class Analytics {
        +query: EventQueries
        +data: DataQueries
        +constructor(biller: Scrawn)
    }

    class EventQueries {
        +basicUsage: BasicUsageBuilder
        +aiToken: AiTokenBuilder
        +payment: PaymentBuilder
    }

    class BasicUsageBuilder {
        +fields: typeof basicUsageFields
        +constructor(grpc, apiKey)
    }

    class BaseEventBuilder~TFields~ {
        +fields: TFields
        +where(condition)
        +orderBy(order)
        +limit(n)
        +aggregate(fn)
        +groupBy(field)
        +execute()
    }

    class basicUsageFields {
        eventId: FieldRef~string~
        eventType: FieldRef~string~
        userId: FieldRef~string~
        reportedTimestamp: FieldRef~string~
        basicUsageType: FieldRef~string~
        debitAmount: FieldRef~number~
    }

    note for BasicUsageBuilder "Replaces deleted SdkEventBuilder\nEvent type: BASIC_USAGE (was SDK_CALL)"

    Analytics --> EventQueries
    EventQueries --> BasicUsageBuilder
    BasicUsageBuilder --|> BaseEventBuilder
    BasicUsageBuilder --> basicUsageFields
Loading

Reviews (1): Last reviewed commit: "chore: release" | Re-trigger Greptile

Comment on lines +1 to +3
---
"@scrawn/analytics": patch
---

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The changeset bump type is patch, but removing sdkEvent from the publicly exported EventQueries interface and replacing it with basicUsage is a breaking change for any consumer currently calling analytics.query.sdkEvent. Per semver, dropping a named property from a published interface requires at minimum a minor bump, and strictly a major if the package is >= 1.0. Existing user code that destructures sdkEvent will fail at runtime with no compile-time warning until they update.

Suggested change
---
"@scrawn/analytics": patch
---
---
"@scrawn/analytics": major
---

Comment on lines +20 to 33
const result1 = await ai.streamText({
model: google("gemini-2.5-flash"),
prompt: "Write a 2 sentence story about a robot.",
onFinish: (event) => {
biller.trackAI({
userId: "c0971bcb-b901-4c3e-a191-c9a97871c39f",
event,
inputDebit: biller.tag("PREMIUM_CALL"),
outputDebit: mul(outputTokens(), 0.0001),
});
},
});

console.log(`Generated: "${await result.text}"\n`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 result1 is assigned but never used — the console.log at the end only reads result.text. Since ai.streamText returns a StreamTextResult, the stream is opened but its output is silently discarded. If the intent is to show the response, result1.text should be logged; if the intent is only to demonstrate the onFinish billing hook, the assignment can be dropped entirely.

Suggested change
const result1 = await ai.streamText({
model: google("gemini-2.5-flash"),
prompt: "Write a 2 sentence story about a robot.",
onFinish: (event) => {
biller.trackAI({
userId: "c0971bcb-b901-4c3e-a191-c9a97871c39f",
event,
inputDebit: biller.tag("PREMIUM_CALL"),
outputDebit: mul(outputTokens(), 0.0001),
});
},
});
console.log(`Generated: "${await result.text}"\n`);
const result1 = await ai.streamText({
model: google("gemini-2.5-flash"),
prompt: "Write a 2 sentence story about a robot.",
onFinish: (event) => {
biller.trackAI({
userId: "c0971bcb-b901-4c3e-a191-c9a97871c39f",
event,
inputDebit: biller.tag("PREMIUM_CALL"),
outputDebit: mul(outputTokens(), 0.0001),
});
},
});
console.log(`Generated (wrapped): "${await result.text}"\n`);
console.log(`Generated (raw): "${await result1.text}"\n`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant