@oxy-hq/sdk 2.1.0 → 2.4.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/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
- import * as React from "react";
3
-
2
+ import { A as UseSemanticQueryOpts, B as CustomerAppErrorReport, C as UseProcedureRunInput, D as UseQueryOpts, E as UseQueryInput, F as useProcedureRun, G as OxyAppFunctionManifest, H as apiErrorFromResponse, I as useQuery, J as _resetCustomerAppManifestCacheForTest, K as OxyAppManifest, L as useResolvedManifest, M as useAgentRun, N as useFunction, O as UseQueryResult, P as useOxyApp, R as useSemanticQuery, S as UseFunctionResult, T as UseProcedureRunResult, U as interpretCustomerAppError, V as OxyApiError, W as LoadManifestOptions, Y as loadCustomerAppManifest, _ as SemanticFilter, a as AppFetcher, b as UseAgentRunInput, c as OxyAppProvider, d as OxyChatProps, f as ProcedureProgress, g as SemanticDateRangeOp, h as SemanticArrayOp, i as AgentSqlArtifact, j as UseSemanticQueryResult, k as UseSemanticQueryInput, l as OxyAppProviderProps, m as ProcedureRunState, n as AgentRunEvent, o as OxyAnswer, p as ProcedureResult, q as ResolvedCustomerAppManifest, r as AgentRunState, s as OxyAnswerProps, t as AgentArtifact, u as OxyChat, v as SemanticScalarOp, w as UseProcedureRunOpts, x as UseAgentRunResult, y as SemanticTimeDimension, z as useTrackEvent } from "./react-BLsczFL4.mjs";
4
3
  //#region src/config.d.ts
5
4
  /**
6
5
  * Configuration for the Oxy SDK
@@ -433,140 +432,6 @@ declare class AnomaliesClient {
433
432
  explain(anomalyId: string): Promise<ExplainResult>;
434
433
  }
435
434
  //#endregion
436
- //#region src/customer-app/manifest.d.ts
437
- /**
438
- * Declaration of a single Oxy Function shipped in the bundle's
439
- * `functions/` dir. See `internal-docs/2026-06-12-customer-apps-functions-design.md`.
440
- *
441
- * All fields optional except that at least one invocation surface
442
- * (`route`, `schedule`, or `airwayStep`) must be active. Absent =
443
- * `route: true` (HTTP-invocable via `useFunction`).
444
- */
445
- interface OxyAppFunctionManifest {
446
- /** Source entry, relative to the app dir. Default: `functions/<name>.ts`. */
447
- entry?: string;
448
- /** Cron expression. When set, the function fires on this schedule. */
449
- schedule?: string;
450
- /** IANA timezone for `schedule`. Default: `UTC`. */
451
- timezone?: string;
452
- /** Expose `POST .../fn/<name>` (called via `useFunction`). Default: true. */
453
- route?: boolean;
454
- /** Wire the function in as an Airway pipeline transform step. */
455
- airwayStep?: {
456
- pipeline: string;
457
- resource: string;
458
- };
459
- /** Wall-clock timeout. Default 30, max 300. */
460
- timeoutSeconds?: number;
461
- /**
462
- * Opt-in result caching for route invocations. Omit (the default) to never
463
- * cache — the safe choice for a side-effectful function (writes, external
464
- * POSTs, ELT). Set `ttlSeconds` ONLY for read-only / idempotent functions:
465
- * results are then cached per (build, function, user, request body) for that
466
- * window, and a repeat `useFunction().invoke(sameBody)` returns the cached
467
- * result without re-running. A `?refresh` query bypasses it.
468
- */
469
- cache?: {
470
- ttlSeconds?: number;
471
- };
472
- /**
473
- * Databases this function's `ctx.warehouse.*` writes may target. Omit (or
474
- * leave empty) and the function may NOT write to any database — writes are
475
- * fail-closed and rejected before any connection is opened. Declare a
476
- * destination here ONLY for a function that legitimately writes to it; a
477
- * read-only function omits it. This scopes writes away from the project's
478
- * source warehouse.
479
- */
480
- destinations?: string[];
481
- }
482
- /** Wire shape of `oxy-app.json` (v2 only). */
483
- interface OxyAppManifest {
484
- /** Must be 2. v1 manifests are no longer supported. */
485
- schemaVersion: 2;
486
- /**
487
- * Optional display name. The admin "Link existing" dialog prefills
488
- * its Name field from this. Omit to let oxy fall back to the
489
- * folder basename.
490
- */
491
- name?: string;
492
- /**
493
- * URL slug. **Required.** The canonical source of truth — the
494
- * dialog locks the slug field to this value, and
495
- * `OXY_APP_BASE_PATH=/customer-apps/<org>/<slug>/` baked into the
496
- * build must match.
497
- */
498
- slug: string;
499
- /**
500
- * Optional org slug. Prefills the dialog's org picker; operator
501
- * can still override. Carries no security weight — the actual
502
- * access check is on the linked row.
503
- */
504
- orgSlug?: string;
505
- /**
506
- * Optional project (workspace) uuid the bundle expects to read
507
- * from. Used by `useQuery` to construct the
508
- * `/api/projects/:id/query` URL.
509
- */
510
- projectId?: string;
511
- /**
512
- * Optional map of Oxy Functions (server-side handlers) shipped in the
513
- * bundle's `functions/` dir, keyed by function name. Omit for a pure
514
- * static bundle (today's default). See the functions design doc.
515
- */
516
- functions?: Record<string, OxyAppFunctionManifest>;
517
- }
518
- /**
519
- * Manifest + runtime-injected identity needed to call oxy. Callers
520
- * should treat this as the only source of truth for "which org/app
521
- * does this bundle belong to."
522
- */
523
- interface ResolvedCustomerAppManifest {
524
- manifest: OxyAppManifest;
525
- /**
526
- * Always an empty array for v2 manifests. Kept for API compatibility;
527
- * callers that previously iterated product names should switch to
528
- * explicit `useQuery` calls.
529
- * @deprecated Will be removed in a future version.
530
- */
531
- productNames: string[];
532
- /** Org slug injected by oxy. */
533
- orgSlug: string;
534
- /** App slug injected by oxy. */
535
- appSlug: string;
536
- /**
537
- * The oxy server's API base URL. Empty string when oxy serves the
538
- * bundle itself (same-origin, the common case); a full URL only
539
- * when the bundle is running under a dev server proxy.
540
- */
541
- apiBaseUrl: string;
542
- /** App UUID; informational. */
543
- appId?: string;
544
- /**
545
- * Project (workspace) UUID. Injection (`window.__OXY_APP__.projectId`)
546
- * wins over the manifest's `projectId` field — the admin row is
547
- * authoritative. Manifest `projectId` is a dev-time hint used only
548
- * when running without a server. Used by `useQuery` to construct the
549
- * `/api/projects/:id/query` URL.
550
- */
551
- projectId?: string;
552
- }
553
- interface LoadManifestOptions {
554
- /**
555
- * Override the URL the manifest is fetched from. Default:
556
- * `<injected_base>/oxy-app.json` or `/oxy-app.json`.
557
- * Useful for non-Next bundlers — set explicitly to wherever your
558
- * bundler emits static assets.
559
- */
560
- manifestUrl?: string;
561
- }
562
- /**
563
- * Load + validate the manifest. Cached after the first call so callers
564
- * can invoke this from every component without coordinating.
565
- */
566
- declare function loadCustomerAppManifest(options?: LoadManifestOptions): Promise<ResolvedCustomerAppManifest>;
567
- /** For tests: reset the cache between runs. */
568
- declare function _resetCustomerAppManifestCacheForTest(): void;
569
- //#endregion
570
435
  //#region src/customer-app/debug.d.ts
571
436
  /** Untyped at the boundary — keep it loose so server-side schema
572
437
  * additions don't break older bundles. Stable enough for inspection
@@ -601,15 +466,117 @@ interface CustomerAppDebugSnapshot {
601
466
  */
602
467
  declare function getCustomerAppDebug(resolved: ResolvedCustomerAppManifest): Promise<CustomerAppDebugSnapshot>;
603
468
  //#endregion
604
- //#region src/customer-app/errors.d.ts
605
- interface CustomerAppErrorReport {
606
- title: string;
607
- message: string;
608
- hint: string;
609
- docs?: string;
469
+ //#region src/customer-app/function-context.d.ts
470
+ /**
471
+ * The request passed as the first argument to a function's default export.
472
+ *
473
+ * The host hands the isolate the raw request body as a string (see
474
+ * `req_json` in `runtime.rs`); parse it yourself, e.g.
475
+ * `JSON.parse(req.body || "{}")`. This is intentionally *not* a full Web
476
+ * `Request` — there is no `.json()` / headers object in v1.
477
+ */
478
+ interface OxyFunctionRequest {
479
+ /** Raw request body as received (JSON string for a JSON POST). */
480
+ body: string;
481
+ }
482
+ /** A single row from a `ctx.query` / `ctx.queryStream` result. */
483
+ type OxyFunctionRow = Record<string, unknown>;
484
+ /** Identity of the invoking user (route) or the system identity (schedule/airway). */
485
+ interface OxyFunctionUser {
486
+ id: string;
487
+ email: string;
488
+ orgId: string;
610
489
  }
611
- /** Interpret a thrown error as a structured report for UI display. */
612
- declare function interpretCustomerAppError(err: unknown): CustomerAppErrorReport;
490
+ /** Result of a `ctx.fetch` call. */
491
+ interface OxyFetchResult {
492
+ status: number;
493
+ body: string;
494
+ }
495
+ /** `ctx.warehouse.*` — writes to one of the app's configured destination databases. */
496
+ interface OxyWarehouseApi {
497
+ insert(database: string, table: string, rows: OxyFunctionRow[]): Promise<unknown>;
498
+ exec(database: string, sql: string): Promise<unknown>;
499
+ upsert(database: string, table: string, rows: OxyFunctionRow[], conflictColumns: string[]): Promise<unknown>;
500
+ }
501
+ /** `ctx.secrets` — write app-scoped secrets (gated by the `secrets.write` capability). */
502
+ interface OxySecretsApi {
503
+ set(key: string, value: string): Promise<void>;
504
+ }
505
+ /** `ctx.semantic` — airlayer-compiled semantic queries (inherits the pre-agg fast path). */
506
+ interface OxySemanticApi {
507
+ query(spec: Record<string, unknown>): Promise<unknown>;
508
+ }
509
+ /** `ctx.airway` — seed/await an Airway ELT pipeline run. */
510
+ interface OxyAirwayApi {
511
+ run(pipelineRef: string, variables?: Record<string, unknown> | null): Promise<{
512
+ runId: string;
513
+ }>;
514
+ }
515
+ /**
516
+ * Input to `ctx.email.send`. Platform-injected: the sender mailbox (`from`) is
517
+ * platform-controlled and **not** an accepted field — passing it is a typed
518
+ * error. Provide `html` and/or `text` as the body (render a template to HTML
519
+ * with `render` from `@oxy-hq/sdk/email`).
520
+ */
521
+ interface EmailSendInput {
522
+ /** Recipient address(es). Required. */
523
+ to: string | string[];
524
+ /** CC address(es). */
525
+ cc?: string | string[];
526
+ /** BCC address(es). */
527
+ bcc?: string | string[];
528
+ /** Reply-To address — the only sender-identity field an author may set. */
529
+ replyTo?: string;
530
+ /** Subject line. Required. */
531
+ subject: string;
532
+ /** HTML body. Provide at least one of `html` / `text`. */
533
+ html?: string;
534
+ /** Plain-text body. Provide at least one of `html` / `text`. */
535
+ text?: string;
536
+ /**
537
+ * Optional idempotency key (≤256 chars). Accepted and validated in v1 but a
538
+ * no-op until the persisted idempotency table lands — adopt it now so
539
+ * background (retried) sends become exactly-once once it does.
540
+ */
541
+ idempotencyKey?: string;
542
+ }
543
+ /** Result of a successful `ctx.email.send`. */
544
+ interface EmailSendResult {
545
+ /** Provider (SES) message id of the sent message. */
546
+ messageId: string;
547
+ }
548
+ /** `ctx.email` — send email (gated by the `email.send` capability). */
549
+ interface OxyEmailApi {
550
+ send(input: EmailSendInput): Promise<EmailSendResult>;
551
+ }
552
+ /**
553
+ * The data-plane context passed as the second argument to a function's default
554
+ * export. Mirrors the host-assembled `ctx` (`__buildCtx` in `runtime.rs`);
555
+ * every member is a host-provided async function bridged to a Rust backend.
556
+ */
557
+ interface OxyFunctionContext {
558
+ /** Invoking user (route) or system identity (schedule/airway). */
559
+ user: OxyFunctionUser;
560
+ /** Read-only view of the app's configured secrets (project-scoped). */
561
+ env: Record<string, string>;
562
+ /** Structured per-invocation logging (captured + surfaced with the response). */
563
+ log(...args: unknown[]): void;
564
+ /** Read-only SQL (SELECT/WITH only), function-scoped row cap. Resolves to the rows. */
565
+ query(sql: string): Promise<OxyFunctionRow[]>;
566
+ /** Read-only SQL with a higher row cap, yielded to the caller in batches. */
567
+ queryStream(sql: string, opts?: {
568
+ batchSize?: number;
569
+ }): AsyncGenerator<OxyFunctionRow[], void, unknown>;
570
+ /** SSRF-allowlisted outbound HTTP with a response-size cap. */
571
+ fetch(url: string, init?: RequestInit): Promise<OxyFetchResult>;
572
+ warehouse: OxyWarehouseApi;
573
+ secrets: OxySecretsApi;
574
+ semantic: OxySemanticApi;
575
+ airway: OxyAirwayApi;
576
+ email: OxyEmailApi;
577
+ }
578
+ /** Signature of a function's default export: `export default async (req, ctx) => Response`. */
579
+ type OxyFunctionHandler = (req: OxyFunctionRequest, ctx: OxyFunctionContext) => Promise<Response> | Response;
613
580
  //#endregion
614
581
  //#region src/customer-app/inject.d.ts
615
582
  /**
@@ -650,440 +617,5 @@ declare function setOxyAppLogger(logger: OxyAppLogger | null): void;
650
617
  /** Used by the SDK internals; not part of the public surface. */
651
618
  declare function getOxyAppLogger(): OxyAppLogger;
652
619
  //#endregion
653
- //#region src/customer-app/function-sse.d.ts
654
- /** A captured `console.*` / `ctx.log` line from a function run. */
655
- interface FunctionLog {
656
- level: string;
657
- message: string;
658
- }
659
- //#endregion
660
- //#region src/customer-app/react.d.ts
661
- /**
662
- * Credentialed fetch wrapper stored in context so `useQuery` can share
663
- * the same request mechanism without coupling it to the global `fetch`.
664
- *
665
- * Sends `credentials: "include"` so the session cookie rides along when
666
- * the app is served by oxy (in-workspace / admin preview) — that cookie
667
- * authorizes data calls. For local dev (cross-origin), the
668
- * `@oxy-hq/vite-plugin` proxy attaches the developer's token. Bundles may
669
- * override the fetcher for test/proxy environments.
670
- */
671
- type AppFetcher = typeof fetch;
672
- interface OxyAppProviderProps {
673
- /** Optional manifest load options. Same shape as `loadCustomerAppManifest`. */
674
- manifestOptions?: LoadManifestOptions;
675
- /**
676
- * Rendered while the manifest is loading. Defaults to nothing; pass a
677
- * spinner if you want one.
678
- */
679
- fallback?: React.ReactNode;
680
- /**
681
- * Rendered on manifest load failure. Receives the structured error
682
- * report so the bundle can show its own branded error card. Defaults
683
- * to a minimal text-only fallback (better than a blank page).
684
- */
685
- errorFallback?: (err: CustomerAppErrorReport) => React.ReactNode;
686
- /**
687
- * Override the fetch implementation used by all hooks (`useQuery`).
688
- * Useful for test environments or proxy setups. Defaults to a wrapper
689
- * that sets `credentials: "include"` on every request.
690
- */
691
- fetcher?: AppFetcher;
692
- children: React.ReactNode;
693
- }
694
- /**
695
- * Top-level provider. Loads the manifest once on mount; children only
696
- * render after the manifest is ready (or the error fallback fires).
697
- */
698
- declare function OxyAppProvider(props: OxyAppProviderProps): React.JSX.Element;
699
- /**
700
- * Error thrown by all customer-app hooks when an API call returns a
701
- * non-2xx response. Carries the structured `code` + `hint` the server
702
- * emits so bundle UIs can render an actionable message instead of
703
- * "404: { ...json... }".
704
- *
705
- * The server contract is documented in
706
- * `crates/app/src/server/api/projects/agent_ask.rs` and
707
- * `procedure_run.rs` — both emit `{ message, code?, hint? }` as JSON.
708
- * Hooks that previously wrapped the raw text in `new Error()` now
709
- * throw this type instead.
710
- */
711
- declare class OxyApiError extends Error {
712
- readonly status: number;
713
- readonly code: string | null;
714
- readonly hint: string | null;
715
- constructor(opts: {
716
- status: number;
717
- message: string;
718
- code?: string | null;
719
- hint?: string | null;
720
- });
721
- }
722
- /**
723
- * Read the resolved manifest from context. Throws if called outside
724
- * `<OxyAppProvider>` — that's a programmer error worth surfacing
725
- * loudly, not silently swallowing.
726
- */
727
- declare function useResolvedManifest(): ResolvedCustomerAppManifest;
728
- interface UseQueryInput {
729
- sql: string;
730
- database?: string;
731
- }
732
- interface UseQueryOpts {
733
- params?: Record<string, string | number | boolean | null | undefined>;
734
- /** Set false to skip the request (e.g., waiting on user input). */
735
- enabled?: boolean;
736
- }
737
- interface UseQueryResult<Row = Record<string, unknown>> {
738
- rows: Row[];
739
- columns: string[];
740
- loading: boolean;
741
- error: Error | null;
742
- refetch: () => void;
743
- }
744
- /**
745
- * Execute an ad-hoc SQL query against the project linked to this
746
- * customer app. The query is specified inline by the caller; no
747
- * manifest declaration is involved.
748
- *
749
- * Re-runs whenever `input` or enabled `params` change. Use the
750
- * `enabled` option to defer the first fetch until required data is
751
- * available (e.g. a user-supplied filter value).
752
- */
753
- declare function useQuery<Row = Record<string, unknown>>(input: UseQueryInput, opts?: UseQueryOpts): UseQueryResult<Row>;
754
- interface UseFunctionResult<Data = unknown> {
755
- /**
756
- * Invoke the function with an optional JSON body. Resolves to the parsed
757
- * result. Pass `{ idempotencyKey }` to make a side-effectful invocation
758
- * exactly-once: a retry with the same key replays the stored result instead
759
- * of re-executing. Send a fresh key per logical action (e.g. a UUID per
760
- * journal entry).
761
- */
762
- invoke: (body?: unknown, opts?: {
763
- idempotencyKey?: string;
764
- }) => Promise<Data>;
765
- /** Last successful result, or null before the first invoke. */
766
- data: Data | null;
767
- /** True while an invocation is in flight. */
768
- isLoading: boolean;
769
- /** Last invocation error, or null. On error this carries `.logs` too. */
770
- error: Error | null;
771
- /**
772
- * `console.*` / `ctx.log` output from the last invoke (success or error), so
773
- * a developer can see what the function printed without opening the oxy
774
- * server logs. Empty for a cache hit or idempotent replay — no run happened,
775
- * so there is nothing to log.
776
- */
777
- logs: FunctionLog[];
778
- }
779
- /**
780
- * Imperative hook for invoking an Oxy Function by name.
781
- *
782
- * ```tsx
783
- * const refresh = useFunction("refresh-sales");
784
- * <button disabled={refresh.isLoading} onClick={() => refresh.invoke({ full: true })}>
785
- * Refresh
786
- * </button>
787
- * ```
788
- */
789
- declare function useFunction<Data = unknown>(name: string): UseFunctionResult<Data>;
790
- /** Scalar filter operators (compared against a single value). */
791
- type SemanticScalarOp = "eq" | "neq" | "lt" | "lte" | "gt" | "gte";
792
- /** Array filter operators (compared against a list). */
793
- type SemanticArrayOp = "in" | "not_in";
794
- /** Date-range filter operators. `from` / `to` accept ISO date strings. */
795
- type SemanticDateRangeOp = "in_date_range" | "not_in_date_range";
796
- /**
797
- * One filter clause. The `field` references a dimension name within
798
- * the topic; the `op` discriminator picks which other fields are
799
- * meaningful. Wire shape matches `agentic_semantic::SemanticFilter`
800
- * verbatim — the bundle's request body is forwarded to airlayer's
801
- * compiler with no translation.
802
- */
803
- type SemanticFilter = {
804
- field: string;
805
- op: SemanticScalarOp;
806
- value: string | number | boolean | null;
807
- } | {
808
- field: string;
809
- op: SemanticArrayOp;
810
- values: Array<string | number | boolean | null>;
811
- } | {
812
- field: string;
813
- op: SemanticDateRangeOp;
814
- from: string;
815
- to: string;
816
- };
817
- /** Time dimensions with optional granularity (e.g. "day", "month"). */
818
- interface SemanticTimeDimension {
819
- dimension: string;
820
- granularity?: "day" | "week" | "month" | "quarter" | "year";
821
- }
822
- interface UseSemanticQueryInput {
823
- topic: string;
824
- dimensions?: string[];
825
- measures?: string[];
826
- time_dimensions?: SemanticTimeDimension[];
827
- filters?: SemanticFilter[];
828
- limit?: number;
829
- }
830
- interface UseSemanticQueryOpts {
831
- /** Set false to skip the request (e.g., waiting on user input). */
832
- enabled?: boolean;
833
- /**
834
- * When true, the response includes the compiled SQL string at
835
- * `sql`. Off by default — production callers shouldn't bake the
836
- * warehouse SQL into their UI. Bundle authors flip this on while
837
- * debugging.
838
- */
839
- debug?: boolean;
840
- }
841
- interface UseSemanticQueryResult<Row = Record<string, unknown>> {
842
- rows: Row[];
843
- columns: string[];
844
- /** True when the result was capped at the server's row limit. */
845
- truncated: boolean;
846
- /** Compiled SQL — populated only when `opts.debug` is true. */
847
- sql: string | null;
848
- loading: boolean;
849
- error: Error | null;
850
- refetch: () => void;
851
- }
852
- /**
853
- * Run a semantic-layer query against the project's `.view.yml` /
854
- * `.topic.yml` definitions. The server compiles to SQL and executes
855
- * through the same connector path as `useQuery`, so result shape
856
- * matches.
857
- *
858
- * Re-runs whenever the input shape changes (deep-compared via JSON).
859
- * Use `opts.enabled = false` to defer the first fetch until required
860
- * inputs (e.g. a user-picked filter value) are available.
861
- */
862
- declare function useSemanticQuery<Row = Record<string, unknown>>(input: UseSemanticQueryInput, opts?: UseSemanticQueryOpts): UseSemanticQueryResult<Row>;
863
- type ProcedureRunState = "idle" | "running" | "done" | "failed";
864
- interface UseProcedureRunInput {
865
- procedureId: string;
866
- }
867
- interface UseProcedureRunOpts {
868
- /** Polling cadence in ms while running. Default: 2000 (procedures
869
- * are typically minutes-long; tighter cadence wastes resources). */
870
- pollIntervalMs?: number;
871
- pollIntervalBackoffMs?: number;
872
- /** Max client-side wait in ms. Default: 1 hour. */
873
- maxWaitMs?: number;
874
- }
875
- interface ProcedureProgress {
876
- step: string;
877
- percent: number;
878
- }
879
- interface ProcedureResult {
880
- summary: string;
881
- outputs: Record<string, unknown>;
882
- }
883
- interface UseProcedureRunResult {
884
- state: ProcedureRunState;
885
- run: (params?: Record<string, unknown>) => void;
886
- /** Cancel the in-flight run. Idempotent. */
887
- cancel: () => void;
888
- progress: ProcedureProgress | null;
889
- result: ProcedureResult | null;
890
- error: Error | null;
891
- }
892
- /**
893
- * @beta Long-running procedure runner. The wire shape works end-to-end
894
- * (start → poll → cancel; runs survive server restarts via the
895
- * `customer_app_procedure_runs` table) but a few rough edges remain
896
- * before this is GA-ready:
897
- *
898
- * - Hint surfaces for `procedure_not_found` are correct but the
899
- * procedure-discovery rules (which directories the server scans,
900
- * case-sensitivity, branch awareness) aren't documented yet.
901
- * - Cancellation across multi-instance deployments leans on a
902
- * periodic sweep — fine for now, but expect occasional latency
903
- * between `cancel()` and the run actually stopping.
904
- * - Progress reporting requires the procedure to emit named
905
- * steps; bundles get `progress: null` until that lands.
906
- *
907
- * The API surface is stable; expect breaking changes only if the
908
- * server-side `customer_app_procedure_runs` schema changes.
909
- */
910
- declare function useProcedureRun(input: UseProcedureRunInput, opts?: UseProcedureRunOpts): UseProcedureRunResult;
911
- type AgentRunState = "idle" | "running" | "needs_clarification" | "done" | "failed";
912
- interface AgentRunEvent {
913
- type: string;
914
- data: unknown;
915
- }
916
- /** SQL produced and (optionally) executed by the agent. Extracted
917
- * from `query_generated` / `query_executed` / `verified_sql` /
918
- * `semantic_query` / `omni_query` SSE events so callers don't have
919
- * to scan the raw event stream themselves. */
920
- interface AgentSqlArtifact {
921
- type: "sql";
922
- /** Stable id derived from the SSE event id so React keys stay
923
- * stable across re-renders / reconnects. */
924
- id: string;
925
- /** Originating UI event type — preserves the verified/semantic/etc.
926
- * flavor in case the renderer wants a badge. */
927
- source: string;
928
- sql: string;
929
- /** Present when the SQL was executed and rows came back. */
930
- results?: {
931
- columns: string[];
932
- rows: unknown[][];
933
- rowCount: number;
934
- };
935
- /** Present when execution failed — surface it so the bundle UI can
936
- * show the failure inline next to the SQL instead of swallowing
937
- * it inside the agent's final answer. */
938
- error?: string;
939
- }
940
- type AgentArtifact = AgentSqlArtifact;
941
- interface UseAgentRunInput {
942
- agentId: string;
943
- }
944
- interface UseAgentRunResult {
945
- state: AgentRunState;
946
- /** Submit a question and open the SSE stream. */
947
- ask: (question: string, opts?: {
948
- threadId?: string;
949
- }) => void;
950
- /** Cancel the in-flight stream + the server-side run. Idempotent. */
951
- cancel: () => void;
952
- /** Accumulated raw events for advanced consumers. */
953
- events: AgentRunEvent[];
954
- /** SQL artifacts extracted from the event stream — convenience
955
- * view over `events` so renderers don't have to know which event
956
- * types carry SQL. */
957
- artifacts: AgentArtifact[];
958
- /** Final answer once a `done` event arrives. Markdown. */
959
- answer: string | null;
960
- /** Clarification text once a suspension event arrives. */
961
- clarification: string | null;
962
- /** Thread id used by the active run (stable across follow-ups). */
963
- threadId: string | null;
964
- /**
965
- * @beta Relative path to the full thread view in oxy (e.g.
966
- * `/threads/<id>` for local mode, or
967
- * `/<org_slug>/workspaces/<ws_id>/threads/<id>` in cloud). Set
968
- * once the run starts so a bundle can render a "Continue in Oxy"
969
- * link without constructing the URL itself.
970
- *
971
- * Caveats while in beta:
972
- * - The bundle's origin and the oxy app shell's origin can
973
- * differ in cloud deployments. If they do, this relative URL
974
- * resolves against the bundle's origin and 404s. A future
975
- * release will expose the oxy app origin via the manifest;
976
- * for now, prefix at the call site if you know your
977
- * deployment topology, or hide the link entirely.
978
- * - The thread row may not be queryable until the run produces
979
- * its first event — clicking the link immediately after
980
- * `ask()` can land on a "thread not found" page.
981
- */
982
- threadUrl: string | null;
983
- error: Error | null;
984
- }
985
- declare function useAgentRun(input: UseAgentRunInput): UseAgentRunResult;
986
- /**
987
- * Engineer-tagged usage event. Free-form `event_name` (≤ 64 chars,
988
- * `[a-z][a-z0-9-]*` validated server-side) + optional JSON `payload`
989
- * (object, ≤ 4 KiB serialized). Surfaces in the admin Activity tab
990
- * grouped by name, with drill-down into recent occurrences.
991
- *
992
- * The handler returned by [`useTrackEvent`] is **fire-and-forget**:
993
- * it enqueues the event into an in-memory batch flushed every second
994
- * (and on `pagehide` so a navigation away doesn't drop the tail).
995
- * No await semantics — call it inline from a click handler without
996
- * awaiting it. Server-side validation errors are logged to the
997
- * console; the call site doesn't need to handle them.
998
- *
999
- * Example:
1000
- * ```tsx
1001
- * const track = useTrackEvent();
1002
- * <button
1003
- * onClick={() => {
1004
- * track("export-clicked", { format: "csv", rowCount });
1005
- * doExport();
1006
- * }}
1007
- * >Export</button>
1008
- * ```
1009
- *
1010
- * Rate-limited at 60/min per (user, app) on the server. A burst that
1011
- * trips the limit drops the excess events with a console warning;
1012
- * within-limit events are unaffected.
1013
- */
1014
- declare function useTrackEvent(): (name: string, payload?: Record<string, unknown>) => void;
1015
- interface OxyAnswerProps {
1016
- /** Markdown answer text from `useAgentRun().answer`. */
1017
- answer: string | null;
1018
- /** SQL artifacts from `useAgentRun().artifacts`. */
1019
- artifacts?: AgentArtifact[];
1020
- /** Lifecycle state — drives the placeholder, spinner, error UI. */
1021
- state: AgentRunState;
1022
- /** Clarification text when `state === "needs_clarification"`. */
1023
- clarification?: string | null;
1024
- /** Failure reason when `state === "failed"`. */
1025
- error?: Error | null;
1026
- /**
1027
- * @beta Relative URL to the thread view in oxy — renders a
1028
- * "Continue in Oxy (beta)" link when set. Pass `null` to suppress
1029
- * the link entirely; the link is marked beta because the resolved
1030
- * URL may not reach a live thread in every deployment topology
1031
- * (see `UseAgentRunResult.threadUrl`).
1032
- */
1033
- threadUrl?: string | null;
1034
- /** Override the link label. Default: "Continue this thread in Oxy". */
1035
- threadLinkLabel?: string;
1036
- /** Maximum number of SQL result rows to render per artifact. Older
1037
- * rows truncated with a "+N more" note. Default: 10. */
1038
- maxArtifactRows?: number;
1039
- /** Class on the outer container — for callers using utility CSS. */
1040
- className?: string;
1041
- }
1042
- /**
1043
- * Renders an agent run's answer + artifacts + thread link as a
1044
- * single block. The default styling is intentionally neutral
1045
- * (system fonts, gray surfaces) so it blends into any bundle.
1046
- *
1047
- * Designed to be paired with `useAgentRun`:
1048
- *
1049
- * ```tsx
1050
- * const run = useAgentRun({ agentId: "analyst" });
1051
- * return (
1052
- * <>
1053
- * <button onClick={() => run.ask("how many users last week?")}>Ask</button>
1054
- * <OxyAnswer {...run} />
1055
- * </>
1056
- * );
1057
- * ```
1058
- */
1059
- declare function OxyAnswer(props: OxyAnswerProps): React.JSX.Element;
1060
- interface OxyChatProps {
1061
- /** Agent id (matches `<id>.agentic.yml` in the project). */
1062
- agentId: string;
1063
- /** Placeholder for the question input. */
1064
- placeholder?: string;
1065
- /** Button label. Default: "Ask". */
1066
- submitLabel?: string;
1067
- /** Rendered when the user hasn't asked anything yet. */
1068
- emptyState?: React.ReactNode;
1069
- /** Forwarded to the inner `<OxyAnswer>`. */
1070
- maxArtifactRows?: number;
1071
- /** Class on the outer container. */
1072
- className?: string;
1073
- }
1074
- /**
1075
- * Complete drop-in chat surface. One agent, one input, one answer
1076
- * view. The chat is single-turn by default — each new question
1077
- * cancels the previous run and clears the answer. Bundles that
1078
- * want a multi-turn conversation history compose their own UI
1079
- * using `useAgentRun` directly.
1080
- *
1081
- * Single-turn keeps the surface dead simple: bundles use this for
1082
- * the "ask anything about your data" widget that sits next to
1083
- * structured panels. Multi-turn is rare in those contexts and
1084
- * better expressed by the bundle.
1085
- */
1086
- declare function OxyChat(props: OxyChatProps): React.JSX.Element;
1087
- //#endregion
1088
- export { type AgentArtifact, type AgentRunEvent, type AgentRunState, type AgentSqlArtifact, AnomaliesClient, type Anomaly, type AnomalySeverity, type AnomalyStatus, type AppFetcher, type CustomerAppDebugSnapshot, type CustomerAppErrorReport, type DimensionOpportunity, type DriverAttribution, type DriverConfidence, type DriverDirection, type DriverForm, type DriverStrength, type EdgeKind, type ExplainConfigOverride, type ExplainNode, type ExplainRequest, type ExplainResult, type ExplainSibling, type ExplainWarning, type ListAnomaliesOptions, type ListAnomaliesResponse, type LoadManifestOptions, type MetricEdge, type MetricNode, type MetricTree, MetricTreeClient, type OpportunityRequest, type OpportunityResult, OxyAnswer, type OxyAnswerProps, OxyApiError, type OxyAppFunctionManifest, type OxyAppLogLevel, type OxyAppLogger, type OxyAppManifest, OxyAppProvider, type OxyAppProviderProps, OxyChat, type OxyChatProps, type OxyInjectedAppConfig, type PredictChange, type PredictImpact, type PredictResult, type ProcedureProgress, type ProcedureResult, type ProcedureRunState, type ResolvedCustomerAppManifest, type ScanOptions, type ScanResponse, type SegmentOpportunity, type SemanticArrayOp, type SemanticDateRangeOp, type SemanticFilter, type SemanticScalarOp, type SemanticTimeDimension, type SensitivityDriver, type SensitivityResult, type SkippedDimension, type SplitKind, type UseAgentRunInput, type UseAgentRunResult, type UseFunctionResult, type UseProcedureRunInput, type UseProcedureRunOpts, type UseProcedureRunResult, type UseQueryInput, type UseQueryOpts, type UseQueryResult, type UseSemanticQueryInput, type UseSemanticQueryOpts, type UseSemanticQueryResult, _resetCustomerAppManifestCacheForTest, getCustomerAppDebug, getOxyAppLogger, interpretCustomerAppError, loadCustomerAppManifest, readInjectedAppConfig, setOxyAppLogger, useAgentRun, useFunction, useProcedureRun, useQuery, useResolvedManifest, useSemanticQuery, useTrackEvent };
620
+ export { type AgentArtifact, type AgentRunEvent, type AgentRunState, type AgentSqlArtifact, AnomaliesClient, type Anomaly, type AnomalySeverity, type AnomalyStatus, type AppFetcher, type CustomerAppDebugSnapshot, type CustomerAppErrorReport, type DimensionOpportunity, type DriverAttribution, type DriverConfidence, type DriverDirection, type DriverForm, type DriverStrength, type EdgeKind, type EmailSendInput, type EmailSendResult, type ExplainConfigOverride, type ExplainNode, type ExplainRequest, type ExplainResult, type ExplainSibling, type ExplainWarning, type ListAnomaliesOptions, type ListAnomaliesResponse, type LoadManifestOptions, type MetricEdge, type MetricNode, type MetricTree, MetricTreeClient, type OpportunityRequest, type OpportunityResult, type OxyAirwayApi, OxyAnswer, type OxyAnswerProps, OxyApiError, type OxyAppFunctionManifest, type OxyAppLogLevel, type OxyAppLogger, type OxyAppManifest, OxyAppProvider, type OxyAppProviderProps, OxyChat, type OxyChatProps, type OxyEmailApi, type OxyFetchResult, type OxyFunctionContext, type OxyFunctionHandler, type OxyFunctionRequest, type OxyFunctionRow, type OxyFunctionUser, type OxyInjectedAppConfig, type OxySecretsApi, type OxySemanticApi, type OxyWarehouseApi, type PredictChange, type PredictImpact, type PredictResult, type ProcedureProgress, type ProcedureResult, type ProcedureRunState, type ResolvedCustomerAppManifest, type ScanOptions, type ScanResponse, type SegmentOpportunity, type SemanticArrayOp, type SemanticDateRangeOp, type SemanticFilter, type SemanticScalarOp, type SemanticTimeDimension, type SensitivityDriver, type SensitivityResult, type SkippedDimension, type SplitKind, type UseAgentRunInput, type UseAgentRunResult, type UseFunctionResult, type UseProcedureRunInput, type UseProcedureRunOpts, type UseProcedureRunResult, type UseQueryInput, type UseQueryOpts, type UseQueryResult, type UseSemanticQueryInput, type UseSemanticQueryOpts, type UseSemanticQueryResult, _resetCustomerAppManifestCacheForTest, apiErrorFromResponse, getCustomerAppDebug, getOxyAppLogger, interpretCustomerAppError, loadCustomerAppManifest, readInjectedAppConfig, setOxyAppLogger, useAgentRun, useFunction, useOxyApp, useProcedureRun, useQuery, useResolvedManifest, useSemanticQuery, useTrackEvent };
1089
621
  //# sourceMappingURL=index.d.mts.map