@agent-native/core 0.35.0 → 0.35.3
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/README.md +1 -1
- package/dist/cli/context-xray-local.d.ts +2 -2
- package/dist/cli/context-xray-local.d.ts.map +1 -1
- package/dist/cli/context-xray-local.js +1449 -53
- package/dist/cli/context-xray-local.js.map +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/create.js +1 -0
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +226 -78
- package/dist/cli/skills.js.map +1 -1
- package/dist/cli/templates-meta.d.ts.map +1 -1
- package/dist/cli/templates-meta.js +8 -4
- package/dist/cli/templates-meta.js.map +1 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +5 -11
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts +6 -0
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +33 -5
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +63 -3
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat.d.ts +39 -3
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +168 -33
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/application-state.d.ts +13 -0
- package/dist/client/application-state.d.ts.map +1 -0
- package/dist/client/application-state.js +99 -0
- package/dist/client/application-state.js.map +1 -0
- package/dist/client/frame-protocol.d.ts +11 -3
- package/dist/client/frame-protocol.d.ts.map +1 -1
- package/dist/client/frame-protocol.js.map +1 -1
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/progress/RunsTray.d.ts +1 -0
- package/dist/client/progress/RunsTray.d.ts.map +1 -1
- package/dist/client/progress/RunsTray.js +50 -16
- package/dist/client/progress/RunsTray.js.map +1 -1
- package/dist/client/use-action.d.ts +12 -0
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +14 -2
- package/dist/client/use-action.js.map +1 -1
- package/dist/client/use-agent-chat-context.d.ts +15 -0
- package/dist/client/use-agent-chat-context.d.ts.map +1 -0
- package/dist/client/use-agent-chat-context.js +32 -0
- package/dist/client/use-agent-chat-context.js.map +1 -0
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +1 -2
- package/dist/deploy/build.js.map +1 -1
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +4 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +33 -4
- package/dist/mcp/server.js.map +1 -1
- package/dist/provider-api/index.d.ts.map +1 -1
- package/dist/provider-api/index.js +14 -6
- package/dist/provider-api/index.js.map +1 -1
- package/dist/server/agent-teams.d.ts +4 -1
- package/dist/server/agent-teams.d.ts.map +1 -1
- package/dist/server/agent-teams.js +104 -28
- package/dist/server/agent-teams.js.map +1 -1
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +21 -11
- package/dist/server/auth.js.map +1 -1
- package/dist/server/request-context.d.ts +3 -4
- package/dist/server/request-context.d.ts.map +1 -1
- package/dist/server/request-context.js.map +1 -1
- package/dist/server/self-dispatch.d.ts.map +1 -1
- package/dist/server/self-dispatch.js +17 -1
- package/dist/server/self-dispatch.js.map +1 -1
- package/dist/server/ssr-handler.d.ts.map +1 -1
- package/dist/server/ssr-handler.js +9 -18
- package/dist/server/ssr-handler.js.map +1 -1
- package/dist/templates/default/AGENTS.md +1 -1
- package/dist/templates/default/DEVELOPING.md +7 -13
- package/dist/templates/default/package.json +3 -3
- package/dist/templates/workspace-core/AGENTS.md +6 -4
- package/dist/templates/workspace-root/AGENTS.md +6 -4
- package/docs/content/actions.md +5 -7
- package/docs/content/client.md +49 -44
- package/docs/content/context-awareness.md +20 -33
- package/docs/content/creating-templates.md +2 -2
- package/docs/content/key-concepts.md +3 -3
- package/docs/content/sharing.md +1 -1
- package/docs/content/template-mail.md +1 -1
- package/docs/content/voice-input.md +1 -1
- package/package.json +11 -7
- package/src/templates/default/AGENTS.md +1 -1
- package/src/templates/default/DEVELOPING.md +7 -13
- package/src/templates/default/package.json +3 -3
- package/src/templates/workspace-core/AGENTS.md +6 -4
- package/src/templates/workspace-root/AGENTS.md +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-action.js","sourceRoot":"","sources":["../../src/client/use-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK9E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,aAAa,GAAG,eAAe,CAAC,wBAAwB,CAAC,CAAC;AAEhE,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,QAAQ,IAAI,KAAK;QACjB,CAAE,KAA8B,CAAC,MAAM,KAAK,GAAG;YAC5C,KAA8B,CAAC,MAAM,KAAK,GAAG,CAAC,CAClD,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAC9B,YAAoB,EACpB,KAAc;IAEd,IAAI,aAAa,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,YAAY,GAAG,CAAC,CAAC;AAC1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O,IAAK,EAAU,CAAC;IAC3B,MAAM,MAAM,GAAG,SAAS,IAAI,MAAM,CAAC;IAKnC,OAAO,WAAW,CAAc;QAC9B,GAAG,WAAW;QACd,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CACrB,WAAW,CAAI,UAAU,EAAE,MAAM,EAAE,MAA6B,CAAC;QACnE,SAAS,EAAE,CAAC,GAAG,IAAqB,EAAE,EAAE;YACtC,oCAAoC;YACpC,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACvD,SAAsB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACrC,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * React Query hooks for calling actions via their auto-mounted HTTP endpoints.\n *\n * Actions are mounted at `/_agent-native/actions/:name` by the framework.\n *\n * ## End-to-end type safety\n *\n * When the action type registry is generated (via the Vite plugin or CLI),\n * `useActionQuery` and `useActionMutation` automatically infer the correct\n * return type and parameter types from the action definitions — no manual\n * type annotations needed.\n *\n * ```ts\n * // Fully typed — return type and params inferred from the action's defineAction()\n * const { data } = useActionQuery(\"list-forms\", { status: \"published\" });\n * // ^? Form[] (inferred from the action's run() return type)\n * ```\n *\n * Without the registry, the hooks fall back to `any` types for backward\n * compatibility.\n */\nimport { useQuery, useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n UseQueryOptions,\n UseMutationOptions,\n} from \"@tanstack/react-query\";\nimport { agentNativePath } from \"./api-path.js\";\nimport { ensureEmbedAuthFetchInterceptor } from \"./embed-auth.js\";\n\nconst ACTION_PREFIX = agentNativePath(\"/_agent-native/actions\");\n\nfunction isAuthFailure(error: unknown): boolean {\n return (\n !!error &&\n typeof error === \"object\" &&\n \"status\" in error &&\n ((error as { status?: unknown }).status === 401 ||\n (error as { status?: unknown }).status === 403)\n );\n}\n\nfunction defaultActionQueryRetry(\n failureCount: number,\n error: unknown,\n): boolean {\n if (isAuthFailure(error)) return false;\n return failureCount < 3;\n}\n\n// ---------------------------------------------------------------------------\n// Action type registry — augmented by generated code\n// ---------------------------------------------------------------------------\n\n/**\n * Action type registry. This interface is empty by default and gets augmented\n * by the auto-generated `.generated/action-types.d.ts` file. When augmented,\n * it maps action names to their parameter and return types, enabling\n * end-to-end type safety for `useActionQuery` and `useActionMutation`.\n */\nexport interface ActionRegistry {}\n\n/** Resolves to the union of registered action names, or `string` if no registry exists. */\ntype ActionName = keyof ActionRegistry extends never\n ? string\n : (keyof ActionRegistry & string) | (string & {});\n\n/** Resolves the return type of an action, or `any` if not in the registry. */\ntype ActionResult<T extends string> = T extends keyof ActionRegistry\n ? ActionRegistry[T] extends { result: infer R }\n ? R\n : any\n : any;\n\n/** Resolves the parameter type of an action, or `Record<string, any>` if not in the registry. */\ntype ActionParams<T extends string> = T extends keyof ActionRegistry\n ? ActionRegistry[T] extends { params: infer P }\n ? P\n : Record<string, any>\n : Record<string, any>;\n\n// ---------------------------------------------------------------------------\n// Fetch helper\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve the browser's IANA timezone (e.g. \"America/Los_Angeles\"). This is\n * sent on every action request as `x-user-timezone` so server-side defaults\n * like \"today\" honor the user's local day rather than the server's UTC clock.\n */\nfunction resolveUserTimezone(): string | undefined {\n try {\n return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function serializeActionQueryParams(\n params: Record<string, any>,\n): string {\n const qs = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n appendActionQueryParam(qs, key, value);\n }\n return qs.toString();\n}\n\nfunction appendActionQueryParam(\n qs: URLSearchParams,\n key: string,\n value: unknown,\n) {\n if (value === null || value === undefined) return;\n if (Array.isArray(value)) {\n // Use bracket keys so a one-item array still arrives as an array after the\n // server parses URLSearchParams. Repeated bare keys lose that distinction.\n for (const item of value) {\n appendActionQueryParam(qs, `${key}[]`, item);\n }\n return;\n }\n qs.append(key, String(value));\n}\n\nasync function actionFetch<T>(\n name: string,\n method: string,\n params?: Record<string, any>,\n): Promise<T> {\n ensureEmbedAuthFetchInterceptor();\n let url = `${ACTION_PREFIX}/${name}`;\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n const tz = resolveUserTimezone();\n if (tz) headers[\"x-user-timezone\"] = tz;\n const init: RequestInit = {\n method,\n headers,\n cache: \"no-store\",\n };\n\n if (method === \"GET\" && params && Object.keys(params).length > 0) {\n // Skip null/undefined so optional filters don't turn into literal \"null\"\n // strings in the query string (e.g. `?folderId=null`).\n const qs = serializeActionQueryParams(params);\n if (qs) url += `?${qs}`;\n } else if (method !== \"GET\" && params) {\n init.body = JSON.stringify(params);\n }\n\n let res: Response;\n try {\n res = await fetch(url, init);\n } catch (err) {\n // Network failures, CORS, server unreachable, etc. — give the caller a\n // useful message instead of the opaque \"Failed to fetch\".\n const cause = err instanceof Error ? err.message : String(err);\n throw new Error(`Action ${name} failed: ${cause}`);\n }\n\n // 204 No Content — nothing to parse.\n if (res.status === 204) return null as T;\n\n // Read the body as text first so we can:\n // - tolerate empty bodies (avoids \"Unexpected end of JSON input\")\n // - surface non-JSON error responses (HTML 401/404 pages, plain text, etc.)\n // - preserve the original HTTP status in the thrown error\n // Track read failures separately from \"no body\" — a stream interruption /\n // decode failure on a 2xx response should error rather than silently\n // succeed with `null`.\n let raw = \"\";\n let readFailed = false;\n let readError: unknown;\n try {\n raw = await res.text();\n } catch (err) {\n readFailed = true;\n readError = err;\n }\n\n let data: any = undefined;\n let parseFailed = false;\n if (raw.length > 0) {\n try {\n data = JSON.parse(raw);\n } catch {\n // Body wasn't JSON — keep `data` undefined and use the raw text below.\n parseFailed = true;\n }\n }\n\n if (!res.ok) {\n const message =\n (data && (data.error || data.message)) ||\n // Truncate non-JSON bodies so we don't dump entire HTML pages into the\n // console, but still give the developer a hint as to what came back.\n (raw && raw.slice(0, 200)) ||\n res.statusText ||\n `HTTP ${res.status}`;\n const error = new Error(`Action ${name} failed: ${message}`);\n (error as any).status = res.status;\n throw error;\n }\n\n // 2xx but the body couldn't even be read (mid-stream abort, decode failure,\n // etc.). Don't silently treat that as a `null` success.\n if (readFailed) {\n const cause =\n readError instanceof Error ? readError.message : String(readError);\n const error = new Error(\n `Action ${name} returned ${res.status} but the body could not be read: ${cause}`,\n );\n (error as any).status = res.status;\n throw error;\n }\n\n // 2xx with a non-empty, non-JSON body. Action callers expect typed data, so\n // returning `null` here would silently mask a real server bug (e.g. a proxy\n // returning HTML 200 instead of JSON). Throw instead — empty bodies (handled\n // above by the `raw.length > 0` guard and the 204 short-circuit) still\n // correctly resolve to `null`.\n if (parseFailed) {\n const error = new Error(\n `Action ${name} returned a non-JSON ${res.status} response: ${raw.slice(0, 200)}`,\n );\n (error as any).status = res.status;\n throw error;\n }\n\n return (data ?? (null as unknown)) as T;\n}\n\n// ---------------------------------------------------------------------------\n// Query hook\n// ---------------------------------------------------------------------------\n\n/**\n * Query an action exposed as GET.\n *\n * When the action type registry is generated, the return type and parameter\n * types are inferred automatically from the action's `defineAction()` call.\n *\n * ```ts\n * // Type-safe — no manual generic needed\n * const { data } = useActionQuery(\"list-meals\", { date: \"2025-01-01\" });\n *\n * // Manual override still works when needed\n * const { data } = useActionQuery<CustomType>(\"list-meals\");\n * ```\n */\nexport function useActionQuery<\n TResult = undefined,\n TName extends ActionName = ActionName,\n>(\n actionName: TName,\n params?: ActionParams<TName>,\n options?: Omit<\n UseQueryOptions<TResult extends undefined ? ActionResult<TName> : TResult>,\n \"queryKey\" | \"queryFn\"\n >,\n) {\n type R = TResult extends undefined ? ActionResult<TName> : TResult;\n return useQuery<R>({\n queryKey: [\"action\", actionName, params],\n queryFn: () => actionFetch<R>(actionName, \"GET\", params),\n retry: defaultActionQueryRetry,\n ...options,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Mutation hook\n// ---------------------------------------------------------------------------\n\n/**\n * Mutate via an action exposed as POST (default), PUT, or DELETE.\n *\n * When the action type registry is generated, the return type and parameter\n * types are inferred automatically.\n *\n * ```ts\n * // Type-safe\n * const { mutate } = useActionMutation(\"log-meal\");\n * mutate({ name: \"Salad\", calories: 350 });\n * ```\n */\nexport function useActionMutation<\n TData = undefined,\n TVariables = undefined,\n TName extends ActionName = ActionName,\n>(\n actionName: TName,\n options?: Omit<\n UseMutationOptions<\n TData extends undefined ? ActionResult<TName> : TData,\n Error,\n TVariables extends undefined ? ActionParams<TName> : TVariables\n >,\n \"mutationFn\"\n > & {\n method?: \"POST\" | \"PUT\" | \"DELETE\";\n },\n) {\n const queryClient = useQueryClient();\n const {\n method: methodOpt,\n onSuccess,\n ...restOptions\n } = options ?? ({} as any);\n const method = methodOpt ?? \"POST\";\n\n type D = TData extends undefined ? ActionResult<TName> : TData;\n type V = TVariables extends undefined ? ActionParams<TName> : TVariables;\n\n return useMutation<D, Error, V>({\n ...restOptions,\n mutationFn: (params) =>\n actionFetch<D>(actionName, method, params as Record<string, any>),\n onSuccess: (...args: [any, any, any]) => {\n // Invalidate related action queries\n queryClient.invalidateQueries({ queryKey: [\"action\"] });\n (onSuccess as Function)?.(...args);\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-action.js","sourceRoot":"","sources":["../../src/client/use-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK9E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,aAAa,GAAG,eAAe,CAAC,wBAAwB,CAAC,CAAC;AAEhE,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,QAAQ,IAAI,KAAK;QACjB,CAAE,KAA8B,CAAC,MAAM,KAAK,GAAG;YAC5C,KAA8B,CAAC,MAAM,KAA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AG,EAAE,CAAC,WAAW,CAAI,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC;QACxD,KAAK,EAAE,uBAAuB;QAC9B,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC;AAED,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAK/B,UAAiB,EACjB,OASC;IAED,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,SAAS,EACT,GAAG,WAAW,EACf,GAAG,OAAO,IAAK,EAAU,CAAC;IAC3B,MAAM,MAAM,GAAG,SAAS,IAAI,MAAM,CAAC;IAKnC,OAAO,WAAW,CAAc;QAC9B,GAAG,WAAW;QACd,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CACrB,WAAW,CAAI,UAAU,EAAE,MAAM,EAAE,MAA6B,CAAC;QACnE,SAAS,EAAE,CAAC,GAAG,IAAqB,EAAE,EAAE;YACtC,oCAAoC;YACpC,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACvD,SAAsB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACrC,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Client helpers for calling actions through the framework transport.\n *\n * Components should prefer `useActionQuery` / `useActionMutation`; use\n * `callAction` for imperative cases such as debounced search, prefetching, or\n * event handlers that do not fit a hook.\n *\n * ## End-to-end type safety\n *\n * When the action type registry is generated (via the Vite plugin or CLI),\n * `useActionQuery` and `useActionMutation` automatically infer the correct\n * return type and parameter types from the action definitions — no manual\n * type annotations needed.\n *\n * ```ts\n * // Fully typed — return type and params inferred from the action's defineAction()\n * const { data } = useActionQuery(\"list-forms\", { status: \"published\" });\n * // ^? Form[] (inferred from the action's run() return type)\n * ```\n *\n * Without the registry, the hooks fall back to `any` types for backward\n * compatibility.\n */\nimport { useQuery, useMutation, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n UseQueryOptions,\n UseMutationOptions,\n} from \"@tanstack/react-query\";\nimport { agentNativePath } from \"./api-path.js\";\nimport { ensureEmbedAuthFetchInterceptor } from \"./embed-auth.js\";\n\nconst ACTION_PREFIX = agentNativePath(\"/_agent-native/actions\");\n\nfunction isAuthFailure(error: unknown): boolean {\n return (\n !!error &&\n typeof error === \"object\" &&\n \"status\" in error &&\n ((error as { status?: unknown }).status === 401 ||\n (error as { status?: unknown }).status === 403)\n );\n}\n\nfunction defaultActionQueryRetry(\n failureCount: number,\n error: unknown,\n): boolean {\n if (isAuthFailure(error)) return false;\n return failureCount < 3;\n}\n\n// ---------------------------------------------------------------------------\n// Action type registry — augmented by generated code\n// ---------------------------------------------------------------------------\n\n/**\n * Action type registry. This interface is empty by default and gets augmented\n * by the auto-generated `.generated/action-types.d.ts` file. When augmented,\n * it maps action names to their parameter and return types, enabling\n * end-to-end type safety for `useActionQuery` and `useActionMutation`.\n */\nexport interface ActionRegistry {}\n\n/** Resolves to the union of registered action names, or `string` if no registry exists. */\ntype ActionName = keyof ActionRegistry extends never\n ? string\n : (keyof ActionRegistry & string) | (string & {});\n\n/** Resolves the return type of an action, or `any` if not in the registry. */\ntype ActionResult<T extends string> = T extends keyof ActionRegistry\n ? ActionRegistry[T] extends { result: infer R }\n ? R\n : any\n : any;\n\n/** Resolves the parameter type of an action, or `Record<string, any>` if not in the registry. */\ntype ActionParams<T extends string> = T extends keyof ActionRegistry\n ? ActionRegistry[T] extends { params: infer P }\n ? P\n : Record<string, any>\n : Record<string, any>;\n\nexport type ClientActionMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\n\nexport interface ClientActionCallOptions {\n method?: ClientActionMethod;\n}\n\n// ---------------------------------------------------------------------------\n// Fetch helper\n// ---------------------------------------------------------------------------\n\n/**\n * Resolve the browser's IANA timezone (e.g. \"America/Los_Angeles\"). This is\n * sent on every action request as `x-user-timezone` so server-side defaults\n * like \"today\" honor the user's local day rather than the server's UTC clock.\n */\nfunction resolveUserTimezone(): string | undefined {\n try {\n return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;\n } catch {\n return undefined;\n }\n}\n\nexport function serializeActionQueryParams(\n params: Record<string, any>,\n): string {\n const qs = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n appendActionQueryParam(qs, key, value);\n }\n return qs.toString();\n}\n\nfunction appendActionQueryParam(\n qs: URLSearchParams,\n key: string,\n value: unknown,\n) {\n if (value === null || value === undefined) return;\n if (Array.isArray(value)) {\n // Use bracket keys so a one-item array still arrives as an array after the\n // server parses URLSearchParams. Repeated bare keys lose that distinction.\n for (const item of value) {\n appendActionQueryParam(qs, `${key}[]`, item);\n }\n return;\n }\n qs.append(key, String(value));\n}\n\nasync function actionFetch<T>(\n name: string,\n method: string,\n params?: Record<string, any>,\n): Promise<T> {\n ensureEmbedAuthFetchInterceptor();\n let url = `${ACTION_PREFIX}/${name}`;\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n const tz = resolveUserTimezone();\n if (tz) headers[\"x-user-timezone\"] = tz;\n const init: RequestInit = {\n method,\n headers,\n cache: \"no-store\",\n };\n\n if (method === \"GET\" && params && Object.keys(params).length > 0) {\n // Skip null/undefined so optional filters don't turn into literal \"null\"\n // strings in the query string (e.g. `?folderId=null`).\n const qs = serializeActionQueryParams(params);\n if (qs) url += `?${qs}`;\n } else if (method !== \"GET\" && params) {\n init.body = JSON.stringify(params);\n }\n\n let res: Response;\n try {\n res = await fetch(url, init);\n } catch (err) {\n // Network failures, CORS, server unreachable, etc. — give the caller a\n // useful message instead of the opaque \"Failed to fetch\".\n const cause = err instanceof Error ? err.message : String(err);\n throw new Error(`Action ${name} failed: ${cause}`);\n }\n\n // 204 No Content — nothing to parse.\n if (res.status === 204) return null as T;\n\n // Read the body as text first so we can:\n // - tolerate empty bodies (avoids \"Unexpected end of JSON input\")\n // - surface non-JSON error responses (HTML 401/404 pages, plain text, etc.)\n // - preserve the original HTTP status in the thrown error\n // Track read failures separately from \"no body\" — a stream interruption /\n // decode failure on a 2xx response should error rather than silently\n // succeed with `null`.\n let raw = \"\";\n let readFailed = false;\n let readError: unknown;\n try {\n raw = await res.text();\n } catch (err) {\n readFailed = true;\n readError = err;\n }\n\n let data: any = undefined;\n let parseFailed = false;\n if (raw.length > 0) {\n try {\n data = JSON.parse(raw);\n } catch {\n // Body wasn't JSON — keep `data` undefined and use the raw text below.\n parseFailed = true;\n }\n }\n\n if (!res.ok) {\n const message =\n (data && (data.error || data.message)) ||\n // Truncate non-JSON bodies so we don't dump entire HTML pages into the\n // console, but still give the developer a hint as to what came back.\n (raw && raw.slice(0, 200)) ||\n res.statusText ||\n `HTTP ${res.status}`;\n const error = new Error(`Action ${name} failed: ${message}`);\n (error as any).status = res.status;\n throw error;\n }\n\n // 2xx but the body couldn't even be read (mid-stream abort, decode failure,\n // etc.). Don't silently treat that as a `null` success.\n if (readFailed) {\n const cause =\n readError instanceof Error ? readError.message : String(readError);\n const error = new Error(\n `Action ${name} returned ${res.status} but the body could not be read: ${cause}`,\n );\n (error as any).status = res.status;\n throw error;\n }\n\n // 2xx with a non-empty, non-JSON body. Action callers expect typed data, so\n // returning `null` here would silently mask a real server bug (e.g. a proxy\n // returning HTML 200 instead of JSON). Throw instead — empty bodies (handled\n // above by the `raw.length > 0` guard and the 204 short-circuit) still\n // correctly resolve to `null`.\n if (parseFailed) {\n const error = new Error(\n `Action ${name} returned a non-JSON ${res.status} response: ${raw.slice(0, 200)}`,\n );\n (error as any).status = res.status;\n throw error;\n }\n\n return (data ?? (null as unknown)) as T;\n}\n\n/**\n * Imperatively call an action from browser/client code.\n *\n * Prefer `useActionQuery` / `useActionMutation` in React render flows. Use this\n * helper when a hook is not ergonomic; do not hand-write fetch calls to\n * `/_agent-native/actions/*` in components.\n */\nexport function callAction<\n TResult = undefined,\n TName extends ActionName = ActionName,\n>(\n actionName: TName,\n params?: ActionParams<TName>,\n options: ClientActionCallOptions = {},\n): Promise<TResult extends undefined ? ActionResult<TName> : TResult> {\n type R = TResult extends undefined ? ActionResult<TName> : TResult;\n return actionFetch<R>(actionName, options.method ?? \"POST\", params);\n}\n\n// ---------------------------------------------------------------------------\n// Query hook\n// ---------------------------------------------------------------------------\n\n/**\n * Query an action exposed as GET.\n *\n * When the action type registry is generated, the return type and parameter\n * types are inferred automatically from the action's `defineAction()` call.\n *\n * ```ts\n * // Type-safe — no manual generic needed\n * const { data } = useActionQuery(\"list-meals\", { date: \"2025-01-01\" });\n *\n * // Manual override still works when needed\n * const { data } = useActionQuery<CustomType>(\"list-meals\");\n * ```\n */\nexport function useActionQuery<\n TResult = undefined,\n TName extends ActionName = ActionName,\n>(\n actionName: TName,\n params?: ActionParams<TName>,\n options?: Omit<\n UseQueryOptions<TResult extends undefined ? ActionResult<TName> : TResult>,\n \"queryKey\" | \"queryFn\"\n >,\n) {\n type R = TResult extends undefined ? ActionResult<TName> : TResult;\n return useQuery<R>({\n queryKey: [\"action\", actionName, params],\n queryFn: () => actionFetch<R>(actionName, \"GET\", params),\n retry: defaultActionQueryRetry,\n ...options,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Mutation hook\n// ---------------------------------------------------------------------------\n\n/**\n * Mutate via an action exposed as POST (default), PUT, or DELETE.\n *\n * When the action type registry is generated, the return type and parameter\n * types are inferred automatically.\n *\n * ```ts\n * // Type-safe\n * const { mutate } = useActionMutation(\"log-meal\");\n * mutate({ name: \"Salad\", calories: 350 });\n * ```\n */\nexport function useActionMutation<\n TData = undefined,\n TVariables = undefined,\n TName extends ActionName = ActionName,\n>(\n actionName: TName,\n options?: Omit<\n UseMutationOptions<\n TData extends undefined ? ActionResult<TName> : TData,\n Error,\n TVariables extends undefined ? ActionParams<TName> : TVariables\n >,\n \"mutationFn\"\n > & {\n method?: \"POST\" | \"PUT\" | \"DELETE\";\n },\n) {\n const queryClient = useQueryClient();\n const {\n method: methodOpt,\n onSuccess,\n ...restOptions\n } = options ?? ({} as any);\n const method = methodOpt ?? \"POST\";\n\n type D = TData extends undefined ? ActionResult<TName> : TData;\n type V = TVariables extends undefined ? ActionParams<TName> : TVariables;\n\n return useMutation<D, Error, V>({\n ...restOptions,\n mutationFn: (params) =>\n actionFetch<D>(actionName, method, params as Record<string, any>),\n onSuccess: (...args: [any, any, any]) => {\n // Invalidate related action queries\n queryClient.invalidateQueries({ queryKey: [\"action\"] });\n (onSuccess as Function)?.(...args);\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type AgentChatContextItem, type AgentChatContextMutationOptions, type AgentChatContextSetOptions, type AgentChatContextState } from "./agent-chat.js";
|
|
2
|
+
export interface UseAgentChatContextResult extends AgentChatContextState {
|
|
3
|
+
set(item: AgentChatContextSetOptions): void;
|
|
4
|
+
remove(key: string): void;
|
|
5
|
+
clear(options?: AgentChatContextMutationOptions): void;
|
|
6
|
+
refresh(): Promise<AgentChatContextState>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Advanced hook for UIs that need to stay in sync with the active chat
|
|
10
|
+
* composer's staged context chips. Simple send/prefill flows should use
|
|
11
|
+
* `sendToAgentChat({ message, context, submit })` directly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useAgentChatContext(): UseAgentChatContextResult;
|
|
14
|
+
export type { AgentChatContextItem };
|
|
15
|
+
//# sourceMappingURL=use-agent-chat-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-agent-chat-context.d.ts","sourceRoot":"","sources":["../../src/client/use-agent-chat-context.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,yBAA0B,SAAQ,qBAAqB;IACtE,GAAG,CAAC,IAAI,EAAE,0BAA0B,GAAG,IAAI,CAAC;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,OAAO,CAAC,EAAE,+BAA+B,GAAG,IAAI,CAAC;IACvD,OAAO,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC3C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,yBAAyB,CA+B/D;AAED,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useCallback, useEffect, useSyncExternalStore } from "react";
|
|
2
|
+
import { clearAgentChatContext, getAgentChatContextState, refreshAgentChatContext, removeAgentChatContextItem, setAgentChatContextItem, subscribeAgentChatContext, } from "./agent-chat.js";
|
|
3
|
+
import { useChangeVersion } from "./use-change-version.js";
|
|
4
|
+
/**
|
|
5
|
+
* Advanced hook for UIs that need to stay in sync with the active chat
|
|
6
|
+
* composer's staged context chips. Simple send/prefill flows should use
|
|
7
|
+
* `sendToAgentChat({ message, context, submit })` directly.
|
|
8
|
+
*/
|
|
9
|
+
export function useAgentChatContext() {
|
|
10
|
+
const appStateVersion = useChangeVersion("app-state");
|
|
11
|
+
const state = useSyncExternalStore(subscribeAgentChatContext, getAgentChatContextState, getAgentChatContextState);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
void refreshAgentChatContext();
|
|
14
|
+
}, [appStateVersion]);
|
|
15
|
+
const set = useCallback((item) => {
|
|
16
|
+
setAgentChatContextItem(item);
|
|
17
|
+
}, []);
|
|
18
|
+
const remove = useCallback((key) => {
|
|
19
|
+
removeAgentChatContextItem(key);
|
|
20
|
+
}, []);
|
|
21
|
+
const clear = useCallback((options) => {
|
|
22
|
+
clearAgentChatContext(options);
|
|
23
|
+
}, []);
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
set,
|
|
27
|
+
remove,
|
|
28
|
+
clear,
|
|
29
|
+
refresh: refreshAgentChatContext,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=use-agent-chat-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-agent-chat-context.js","sourceRoot":"","sources":["../../src/client/use-agent-chat-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,GAK1B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAS3D;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,eAAe,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,oBAAoB,CAChC,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,CACzB,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,uBAAuB,EAAE,CAAC;IACjC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,IAAgC,EAAE,EAAE;QAC3D,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,GAAW,EAAE,EAAE;QACzC,0BAA0B,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,OAAyC,EAAE,EAAE;QACtE,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,GAAG,KAAK;QACR,GAAG;QACH,MAAM;QACN,KAAK;QACL,OAAO,EAAE,uBAAuB;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback, useEffect, useSyncExternalStore } from \"react\";\nimport {\n clearAgentChatContext,\n getAgentChatContextState,\n refreshAgentChatContext,\n removeAgentChatContextItem,\n setAgentChatContextItem,\n subscribeAgentChatContext,\n type AgentChatContextItem,\n type AgentChatContextMutationOptions,\n type AgentChatContextSetOptions,\n type AgentChatContextState,\n} from \"./agent-chat.js\";\nimport { useChangeVersion } from \"./use-change-version.js\";\n\nexport interface UseAgentChatContextResult extends AgentChatContextState {\n set(item: AgentChatContextSetOptions): void;\n remove(key: string): void;\n clear(options?: AgentChatContextMutationOptions): void;\n refresh(): Promise<AgentChatContextState>;\n}\n\n/**\n * Advanced hook for UIs that need to stay in sync with the active chat\n * composer's staged context chips. Simple send/prefill flows should use\n * `sendToAgentChat({ message, context, submit })` directly.\n */\nexport function useAgentChatContext(): UseAgentChatContextResult {\n const appStateVersion = useChangeVersion(\"app-state\");\n const state = useSyncExternalStore(\n subscribeAgentChatContext,\n getAgentChatContextState,\n getAgentChatContextState,\n );\n\n useEffect(() => {\n void refreshAgentChatContext();\n }, [appStateVersion]);\n\n const set = useCallback((item: AgentChatContextSetOptions) => {\n setAgentChatContextItem(item);\n }, []);\n\n const remove = useCallback((key: string) => {\n removeAgentChatContextItem(key);\n }, []);\n\n const clear = useCallback((options?: AgentChatContextMutationOptions) => {\n clearAgentChatContext(options);\n }, []);\n\n return {\n ...state,\n set,\n remove,\n clear,\n refresh: refreshAgentChatContext,\n };\n}\n\nexport type { AgentChatContextItem };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;GAYG;AAOH,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAkD7B,wBAAgB,wCAAwC,CACtD,WAAW,EAAE,MA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ED
|
@@ -411,8 +411,7 @@ function shouldUseDefaultSsrCacheHeader(headers, status, pathname) {
|
|
|
411
411
|
// data fetches fill CDN cache instead of bypassing it and slamming origin.
|
|
412
412
|
// Do not re-add a blanket auth-signal bypass here; logged-in browsers still
|
|
413
413
|
// need CDN-cached public route data. Worker SSR does not populate
|
|
414
|
-
// getRequestUserEmail()/accessFilter() context for private loaders
|
|
415
|
-
// Node/H3 has an auth-context access guard for older loaders that still do.
|
|
414
|
+
// getRequestUserEmail()/accessFilter() context for private loaders.
|
|
416
415
|
// Also do not preserve route-level private/no-store for React Router .data:
|
|
417
416
|
// if a route needs per-user data, it belongs behind a client-side action/API
|
|
418
417
|
// call rather than in the shared SSR payload.
|