@w6w/embed 0.2.23 → 0.2.24

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.
@@ -1 +1 @@
1
- {"version":3,"file":"repos.mjs","sources":["../src/repos/agents-studio-agents.ts","../src/repos/agents-studio-assets.ts"],"sourcesContent":["/**\n * The Agents Studio repo — agent drafts, ready-only skill/context pickers, model routes,\n * agent settings and storage bindings over `@w6w/sdk` (`agents.*`, `skills.*`, `context.*`,\n * `console.storage.*`). Query-key factory + react-query hooks, mirroring `documents.ts`.\n *\n * Agents are DRAFTS: `runnable` is always `false` (A22). A save sends the body `revision` and\n * the precondition header from the loaded `updatedAt`; a 409 is surfaced as a typed\n * {@linkcode AgentConflictError} and is never retried or overwritten (A18).\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport {\n type Agent,\n ApiError,\n type ContextEntry,\n type ContextPin,\n type CreateAgentInput,\n type SkillPin,\n type SkillVersion,\n type UpdateAgentInput,\n type W6WClient,\n} from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\nimport { listModelRoutes } from \"./models.ts\";\n\nexport type {\n Agent,\n ContextEntry,\n ContextPin,\n CreateAgentInput,\n SkillPin,\n SkillVersion,\n UpdateAgentInput,\n};\n\n/** Thrown by {@linkcode updateAgent} on a 409: the draft changed elsewhere. Never overwrites. */\nexport class AgentConflictError extends Error {\n readonly kind = \"conflict\" as const;\n /** The server's current revision, when the error body carried one. */\n readonly currentRevision: number | null;\n readonly cause: ApiError;\n constructor(cause: ApiError) {\n super(\"This agent changed elsewhere — reload to see the latest version.\");\n this.name = \"AgentConflictError\";\n this.cause = cause;\n this.currentRevision = currentRevisionOf(cause.raw);\n }\n}\n\nfunction currentRevisionOf(raw: unknown): number | null {\n const o = raw as {\n revision?: unknown;\n error?: { revision?: unknown; details?: { revision?: unknown } };\n } | null;\n const v = o?.revision ?? o?.error?.revision ?? o?.error?.details?.revision;\n return typeof v === \"number\" ? v : null;\n}\n\n/** True for a {@linkcode AgentConflictError}. */\nexport function isAgentConflict(e: unknown): e is AgentConflictError {\n return e instanceof AgentConflictError;\n}\n\nexport const agentsKey = (includeArchived = false) => [\"agents\", { includeArchived }] as const;\nexport const agentKey = (id: string) => [\"agents\", \"detail\", id] as const;\nexport const agentSkillVersionsKey = (skillId: string) =>\n [\"agents\", \"skill-versions\", skillId] as const;\nexport const agentSkillsKey = () => [\"agents\", \"skills\"] as const;\nexport const agentContextKey = () => [\"agents\", \"context\"] as const;\nexport const agentContextEntriesKey = (collectionId: string) =>\n [\"agents\", \"context-entries\", collectionId] as const;\nexport const agentAllContextEntriesKey = () => [\"agents\", \"context-entries-all\"] as const;\nexport const agentModelRoutesKey = (projectId?: string) =>\n [\"agents\", \"model-routes\", projectId] as const;\nexport const agentSettingsKey = () => [\"agent-settings\"] as const;\nexport const storageBindingsKey = () => [\"agent-settings\", \"storage-bindings\"] as const;\n\n/** Save an agent: `revision` in the body, `updatedAt` as the precondition header; 409 → conflict. */\nexport async function updateAgent(\n client: W6WClient,\n id: string,\n patch: Omit<UpdateAgentInput, \"revision\">,\n loaded: Pick<Agent, \"revision\" | \"updatedAt\">,\n): Promise<Agent> {\n try {\n return await client.agents.update(\n id,\n { ...patch, revision: loaded.revision },\n { ifUnmodifiedSince: loaded.updatedAt },\n );\n } catch (e) {\n if (e instanceof ApiError && e.status === 409) throw new AgentConflictError(e);\n throw e;\n }\n}\n\n/** Readiness of a pin against the ready-only picker lists. */\nexport type PinState = \"ready\" | \"unavailable\";\n\n/** A skill pin is `ready` only when its version is among the ready versions of its skill. */\nexport function skillPinState(\n pin: SkillPin,\n readyVersions: readonly SkillVersion[] | undefined,\n): PinState {\n return readyVersions?.some((v) => v.id === pin.skillVersionId && v.skillId === pin.skillId)\n ? \"ready\"\n : \"unavailable\";\n}\n\n/** A context pin is `ready` only when its entry is listed, unarchived, at the pinned version. */\nexport function contextPinState(\n pin: ContextPin,\n entries: readonly ContextEntry[] | undefined,\n): PinState {\n return entries?.some((e) => e.assetVersionId === pin.assetVersionId && e.archivedAt == null)\n ? \"ready\"\n : \"unavailable\";\n}\n\n/** Picker options: ready (listed, unarchived) context entries only. */\nexport function readyContextEntries(entries: readonly ContextEntry[]): ContextEntry[] {\n return entries.filter((e) => e.archivedAt == null);\n}\n\nexport function useAgentsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentsKey(includeArchived),\n queryFn: () => client.agents.list({ includeArchived }),\n });\n}\n\nexport function useAgentQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentKey(id ?? \"\"),\n enabled: !!id,\n queryFn: () => client.agents.get(id as string),\n });\n}\n\nexport function useCreateAgent() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateAgentInput) => client.agents.create(input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"agents\"] }),\n });\n}\n\nexport function useUpdateAgent(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: {\n patch: Omit<UpdateAgentInput, \"revision\">;\n loaded: Pick<Agent, \"revision\" | \"updatedAt\">;\n }) => updateAgent(client, id, v.patch, v.loaded),\n onSuccess: (agent) => {\n qc.setQueryData(agentKey(id), agent);\n return qc.invalidateQueries({ queryKey: [\"agents\"] });\n },\n });\n}\n\nexport function useArchiveAgent() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.agents.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"agents\"] }),\n });\n}\n\nexport function useAgentSkillsQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: agentSkillsKey(), queryFn: () => client.skills.list() });\n}\n\nexport function useAgentSkillVersionsQuery(skillId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentSkillVersionsKey(skillId ?? \"\"),\n enabled: !!skillId,\n queryFn: () => client.skills.versions(skillId as string),\n });\n}\n\nexport function useAgentContextCollectionsQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: agentContextKey(), queryFn: () => client.context.list() });\n}\n\nexport function useAgentContextEntriesQuery(collectionId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentContextEntriesKey(collectionId ?? \"\"),\n enabled: !!collectionId,\n queryFn: () => client.context.entries.list(collectionId as string),\n });\n}\n\n/** Every doc visible to the caller (collection-less included) — the pin picker's source. */\nexport function useAgentAllContextEntriesQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentAllContextEntriesKey(),\n queryFn: () => client.contextEntries.list({}),\n });\n}\n\nexport function useAgentModelRoutesQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentModelRoutesKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelRoutes(client, projectId as string),\n });\n}\n\nexport function useAgentSettingsQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentSettingsKey(),\n queryFn: () => client.console.storage.settings.get(),\n });\n}\n\nexport function usePatchAgentSettings() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (patch: Parameters<W6WClient[\"console\"][\"storage\"][\"settings\"][\"patch\"]>[0]) =>\n client.console.storage.settings.patch(patch),\n onSuccess: (s) => {\n qc.setQueryData(agentSettingsKey(), s);\n },\n });\n}\n\nexport function useStorageBindingsQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: storageBindingsKey(),\n queryFn: () => client.console.storage.bindings.list(),\n });\n}\n","/**\n * Agents Studio asset hooks — skills, context collections/entries and stored asset files over\n * `W6WClient`'s `skills.*`, `context.*` and `assets.*` (react-query, same shape as `vars.ts`).\n *\n * These are tenant/account-scoped (no `project` is sent). Uploads are byte-mode: the caller\n * hashes and PUTs the same bytes (see Studio's `agents-studio/upload.ts`); this module only\n * wraps the single-call operations.\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n AssetUploadCreateInput,\n CreateContextCollectionInput,\n CreateStandaloneContextEntryInput,\n UpdateContextEntryInput,\n} from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\n\nexport const skillsKey = (includeArchived = false) => [\"skills\", { includeArchived }] as const;\nexport const skillKey = (id: string) => [\"skills\", id] as const;\nexport const skillVersionsKey = (id: string) => [\"skills\", id, \"versions\"] as const;\nexport const contextCollectionsKey = (includeArchived = false) =>\n [\"context-collections\", { includeArchived }] as const;\nexport const contextCollectionKey = (id: string) => [\"context-collections\", id] as const;\nexport const contextEntriesKey = (id: string, includeArchived = false) =>\n [\"context-collections\", id, \"entries\", { includeArchived }] as const;\nexport const allContextEntriesKey = (includeArchived = false) =>\n [\"context-entries\", { includeArchived }] as const;\nexport const assetVersionsKey = (id: string) => [\"assets\", id, \"versions\"] as const;\nexport const assetFilesKey = (id: string, versionId: string) =>\n [\"assets\", id, \"versions\", versionId, \"files\"] as const;\n\n// ── Skills ──────────────────────────────────────────────────────────────────────────────────\n\nexport function useSkillsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillsKey(includeArchived),\n queryFn: () => client.skills.list({ includeArchived }),\n });\n}\n\nexport function useSkillQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.skills.get(id as string),\n });\n}\n\nexport function useSkillVersionsQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillVersionsKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.skills.versions(id as string),\n });\n}\n\nexport function useArchiveSkillMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.skills.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"skills\"] }),\n });\n}\n\n// ── Context collections + entries ───────────────────────────────────────────────────────────\n\nexport function useContextCollectionsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextCollectionsKey(includeArchived),\n queryFn: () => client.context.list({ includeArchived }),\n });\n}\n\nexport function useContextCollectionQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextCollectionKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.context.get(id as string),\n });\n}\n\nexport function useCreateContextCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateContextCollectionInput) => client.context.create(input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"context-collections\"] }),\n });\n}\n\nexport function useContextEntriesQuery(collectionId: string | undefined, includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextEntriesKey(collectionId ?? \"\", includeArchived),\n enabled: collectionId != null,\n queryFn: () => client.context.entries.list(collectionId as string, { includeArchived }),\n });\n}\n\n/** Edit-as-new-version: `PUT` creates the next version; `ifUnmodifiedSince` guards a stale edit. */\nexport function useUpdateContextEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: {\n collectionId: string;\n entryId: string;\n input: UpdateContextEntryInput;\n ifUnmodifiedSince?: string;\n }) =>\n client.context.entries.update(v.collectionId, v.entryId, v.input, {\n ifUnmodifiedSince: v.ifUnmodifiedSince,\n }),\n onSuccess: (_r, v) => {\n qc.invalidateQueries({ queryKey: [\"context-collections\", v.collectionId] });\n qc.invalidateQueries({ queryKey: [\"assets\"] });\n },\n });\n}\n\n// ── Collection-independent entries (`client.contextEntries.*`) ──────────────────────────────\n\n/** Every doc visible to the caller, whether or not it is in a collection. */\nexport function useAllContextEntriesQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: allContextEntriesKey(includeArchived),\n queryFn: () => client.contextEntries.list({ includeArchived }),\n });\n}\n\n/** Invalidate the all-docs list and, per affected collection, its entries list. */\nfunction invalidateEntries(qc: ReturnType<typeof useQueryClient>, collectionIds: string[] = []) {\n qc.invalidateQueries({ queryKey: [\"context-entries\"] });\n for (const id of collectionIds) qc.invalidateQueries({ queryKey: contextEntriesKey(id) });\n}\n\n/** Create a text doc, private unless `collectionIds` / `visibility` say otherwise. */\nexport function useCreateContextEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateStandaloneContextEntryInput) => client.contextEntries.create(input),\n onSuccess: (_r, v) => invalidateEntries(qc, v.collectionIds),\n });\n}\n\nexport function useAddEntryToCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { entryId: string; collectionId: string }) =>\n client.contextEntries.addToCollection(v.entryId, v.collectionId),\n onSuccess: (_r, v) => invalidateEntries(qc, [v.collectionId]),\n });\n}\n\nexport function useRemoveEntryFromCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { entryId: string; collectionId: string }) =>\n client.contextEntries.removeFromCollection(v.entryId, v.collectionId),\n onSuccess: (_r, v) => invalidateEntries(qc, [v.collectionId]),\n });\n}\n\n// ── Asset versions, files, downloads ────────────────────────────────────────────────────────\n\nexport function useAssetVersionsQuery(assetId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: assetVersionsKey(assetId ?? \"\"),\n enabled: assetId != null,\n queryFn: () => client.assets.versions(assetId as string),\n });\n}\n\nexport function useAssetFilesQuery(assetId: string | undefined, versionId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: assetFilesKey(assetId ?? \"\", versionId ?? \"\"),\n enabled: assetId != null && versionId != null,\n queryFn: () => client.assets.files(assetId as string, versionId as string),\n });\n}\n\n/** Exact bytes of one file. A mutation (not a query): downloads are user-triggered, never cached. */\nexport function useDownloadAssetFileMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { assetId: string; versionId: string; fileId: string }) =>\n client.assets.content(v.assetId, v.versionId, v.fileId),\n });\n}\n\n/** One version as a store-only ZIP. */\nexport function useDownloadAssetArchiveMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { assetId: string; versionId: string }) =>\n client.assets.archiveDownload(v.assetId, v.versionId),\n });\n}\n\nexport function useArchiveAssetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.assets.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"assets\"] }),\n });\n}\n\n// ── Upload (resumable, byte-mode) ───────────────────────────────────────────────────────────\n\nexport function useCreateAssetUploadMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (input: AssetUploadCreateInput) => client.assets.uploads.create(input),\n });\n}\n\nexport function usePutAssetUploadEntryMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { uploadId: string; index: number; bytes: Uint8Array }) =>\n client.assets.uploads.putEntry(v.uploadId, v.index, v.bytes),\n });\n}\n\n/** Publishing a version changes skills, context and assets alike — invalidate all three. */\nexport function useFinalizeAssetUploadMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (uploadId: string) => client.assets.uploads.finalize(uploadId),\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: [\"skills\"] });\n qc.invalidateQueries({ queryKey: [\"context-collections\"] });\n qc.invalidateQueries({ queryKey: [\"assets\"] });\n },\n });\n}\n\nexport function useAbortAssetUploadMutation() {\n const client = useEmbedClient();\n return useMutation({ mutationFn: (uploadId: string) => client.assets.uploads.abort(uploadId) });\n}\n"],"names":["AgentConflictError","cause","__publicField","currentRevisionOf","raw","o","v","_a","_c","_b","isAgentConflict","agentsKey","includeArchived","agentKey","id","agentSkillVersionsKey","skillId","agentSkillsKey","agentContextKey","agentContextEntriesKey","collectionId","agentAllContextEntriesKey","agentModelRoutesKey","projectId","agentSettingsKey","storageBindingsKey","updateAgent","client","patch","loaded","e","ApiError","skillPinState","pin","readyVersions","contextPinState","entries","readyContextEntries","useAgentsQuery","useEmbedClient","useQuery","useAgentQuery","useCreateAgent","qc","useQueryClient","useMutation","input","useUpdateAgent","agent","useArchiveAgent","useAgentSkillsQuery","useAgentSkillVersionsQuery","useAgentContextCollectionsQuery","useAgentContextEntriesQuery","useAgentAllContextEntriesQuery","useAgentModelRoutesQuery","listModelRoutes","useAgentSettingsQuery","usePatchAgentSettings","useStorageBindingsQuery","skillsKey","skillKey","skillVersionsKey","contextCollectionsKey","contextCollectionKey","contextEntriesKey","allContextEntriesKey","assetVersionsKey","assetFilesKey","versionId","useSkillsQuery","useSkillQuery","useSkillVersionsQuery","useArchiveSkillMutation","useContextCollectionsQuery","useContextCollectionQuery","useCreateContextCollectionMutation","useContextEntriesQuery","useUpdateContextEntryMutation","_r","useAllContextEntriesQuery","invalidateEntries","collectionIds","useCreateContextEntryMutation","useAddEntryToCollectionMutation","useRemoveEntryFromCollectionMutation","useAssetVersionsQuery","assetId","useAssetFilesQuery","useDownloadAssetFileMutation","useDownloadAssetArchiveMutation","useArchiveAssetMutation","useCreateAssetUploadMutation","usePutAssetUploadEntryMutation","useFinalizeAssetUploadMutation","uploadId","useAbortAssetUploadMutation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmCO,MAAMA,UAA2B,MAAM;AAAA,EAK5C,YAAYC,GAAiB;AAC3B,UAAM,kEAAkE;AALjE,IAAAC,EAAA,cAAO;AAEP;AAAA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAGP,SAAK,OAAO,sBACZ,KAAK,QAAQD,GACb,KAAK,kBAAkBE,EAAkBF,EAAM,GAAG;AAAA,EACpD;AACF;AAEA,SAASE,EAAkBC,GAA6B;;AACtD,QAAMC,IAAID,GAIJE,KAAID,KAAA,gBAAAA,EAAG,eAAYE,IAAAF,KAAA,gBAAAA,EAAG,UAAH,gBAAAE,EAAU,eAAYC,KAAAC,IAAAJ,KAAA,gBAAAA,EAAG,UAAH,gBAAAI,EAAU,YAAV,gBAAAD,EAAmB;AAClE,SAAO,OAAOF,KAAM,WAAWA,IAAI;AACrC;AAGO,SAASI,EAAg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7CA,EAAG,kBAAkB,EAAE,UAAU,CAAC,qBAAqB,GAAG,GAC1DA,EAAG,kBAAkB,EAAE,UAAU,CAAC,QAAQ,GAAG;AAAA,IAC/C;AAAA,EAAA,CACD;AACH;AAEO,SAASqD,KAA8B;AAC5C,QAAMrE,IAASY,EAAA;AACf,SAAOM,EAAY,EAAE,YAAY,CAACkD,MAAqBpE,EAAO,OAAO,QAAQ,MAAMoE,CAAQ,GAAG;AAChG;"}
1
+ {"version":3,"file":"repos.mjs","sources":["../src/repos/agents-studio-agents.ts","../src/repos/agents-studio-assets.ts"],"sourcesContent":["/**\n * The Agents Studio repo — agent drafts, ready-only skill/context pickers, model routes,\n * agent settings and storage bindings over `@w6w/sdk` (`agents.*`, `skills.*`, `context.*`,\n * `console.storage.*`). Query-key factory + react-query hooks, mirroring `documents.ts`.\n *\n * Agents are DRAFTS: `runnable` is always `false` (A22). A save sends the body `revision` and\n * the precondition header from the loaded `updatedAt`; a 409 is surfaced as a typed\n * {@linkcode AgentConflictError} and is never retried or overwritten (A18).\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport {\n path,\n type Agent,\n type AgentTool,\n ApiError,\n type ContextEntry,\n type ContextPin,\n type CreateAgentInput,\n type SkillPin,\n type SkillVersion,\n type UpdateAgentInput,\n type W6WClient,\n} from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\nimport { listModelRoutes } from \"./models.ts\";\n\nexport type {\n Agent,\n AgentTool,\n ContextEntry,\n ContextPin,\n CreateAgentInput,\n SkillPin,\n SkillVersion,\n UpdateAgentInput,\n};\n\n/** Thrown by {@linkcode updateAgent} on a 409: the draft changed elsewhere. Never overwrites. */\nexport class AgentConflictError extends Error {\n readonly kind = \"conflict\" as const;\n /** The server's current revision, when the error body carried one. */\n readonly currentRevision: number | null;\n readonly cause: ApiError;\n constructor(cause: ApiError) {\n super(\"This agent changed elsewhere — reload to see the latest version.\");\n this.name = \"AgentConflictError\";\n this.cause = cause;\n this.currentRevision = currentRevisionOf(cause.raw);\n }\n}\n\nfunction currentRevisionOf(raw: unknown): number | null {\n const o = raw as {\n revision?: unknown;\n error?: { revision?: unknown; details?: { revision?: unknown } };\n } | null;\n const v = o?.revision ?? o?.error?.revision ?? o?.error?.details?.revision;\n return typeof v === \"number\" ? v : null;\n}\n\n/** True for a {@linkcode AgentConflictError}. */\nexport function isAgentConflict(e: unknown): e is AgentConflictError {\n return e instanceof AgentConflictError;\n}\n\nexport const agentsKey = (includeArchived = false) => [\"agents\", { includeArchived }] as const;\nexport const agentKey = (id: string) => [\"agents\", \"detail\", id] as const;\nexport const agentSkillVersionsKey = (skillId: string) =>\n [\"agents\", \"skill-versions\", skillId] as const;\nexport const agentSkillsKey = () => [\"agents\", \"skills\"] as const;\nexport const agentContextKey = () => [\"agents\", \"context\"] as const;\nexport const agentContextEntriesKey = (collectionId: string) =>\n [\"agents\", \"context-entries\", collectionId] as const;\nexport const agentAllContextEntriesKey = () => [\"agents\", \"context-entries-all\"] as const;\nexport const agentModelRoutesKey = (projectId?: string) =>\n [\"agents\", \"model-routes\", projectId] as const;\nexport const agentSettingsKey = () => [\"agent-settings\"] as const;\nexport const storageBindingsKey = () => [\"agent-settings\", \"storage-bindings\"] as const;\n\n/** Save an agent: `revision` in the body, `updatedAt` as the precondition header; 409 → conflict. */\nexport async function updateAgent(\n client: W6WClient,\n id: string,\n patch: Omit<UpdateAgentInput, \"revision\">,\n loaded: Pick<Agent, \"revision\" | \"updatedAt\">,\n): Promise<Agent> {\n try {\n return await client.agents.update(\n id,\n { ...patch, revision: loaded.revision },\n { ifUnmodifiedSince: loaded.updatedAt },\n );\n } catch (e) {\n if (e instanceof ApiError && e.status === 409) throw new AgentConflictError(e);\n throw e;\n }\n}\n\n/** Readiness of a pin against the ready-only picker lists. */\nexport type PinState = \"ready\" | \"unavailable\";\n\n/** A skill pin is `ready` only when its version is among the ready versions of its skill. */\nexport function skillPinState(\n pin: SkillPin,\n readyVersions: readonly SkillVersion[] | undefined,\n): PinState {\n return readyVersions?.some((v) => v.id === pin.skillVersionId && v.skillId === pin.skillId)\n ? \"ready\"\n : \"unavailable\";\n}\n\n/** A context pin is `ready` only when its entry is listed, unarchived, at the pinned version. */\nexport function contextPinState(\n pin: ContextPin,\n entries: readonly ContextEntry[] | undefined,\n): PinState {\n return entries?.some((e) => e.assetVersionId === pin.assetVersionId && e.archivedAt == null)\n ? \"ready\"\n : \"unavailable\";\n}\n\n/** Picker options: ready (listed, unarchived) context entries only. */\nexport function readyContextEntries(entries: readonly ContextEntry[]): ContextEntry[] {\n return entries.filter((e) => e.archivedAt == null);\n}\n\nexport function useAgentsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentsKey(includeArchived),\n queryFn: () => client.agents.list({ includeArchived }),\n });\n}\n\nexport function useAgentQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentKey(id ?? \"\"),\n enabled: !!id,\n queryFn: () => client.agents.get(id as string),\n });\n}\n\nexport function useCreateAgent() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateAgentInput) => client.agents.create(input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"agents\"] }),\n });\n}\n\nexport function useUpdateAgent(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: {\n patch: Omit<UpdateAgentInput, \"revision\">;\n loaded: Pick<Agent, \"revision\" | \"updatedAt\">;\n }) => updateAgent(client, id, v.patch, v.loaded),\n onSuccess: (agent) => {\n qc.setQueryData(agentKey(id), agent);\n return qc.invalidateQueries({ queryKey: [\"agents\"] });\n },\n });\n}\n\nexport function useArchiveAgent() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.agents.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"agents\"] }),\n });\n}\n\nexport function useAgentSkillsQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: agentSkillsKey(), queryFn: () => client.skills.list() });\n}\n\nexport function useAgentSkillVersionsQuery(skillId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentSkillVersionsKey(skillId ?? \"\"),\n enabled: !!skillId,\n queryFn: () => client.skills.versions(skillId as string),\n });\n}\n\nexport function useAgentContextCollectionsQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: agentContextKey(), queryFn: () => client.context.list() });\n}\n\nexport function useAgentContextEntriesQuery(collectionId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentContextEntriesKey(collectionId ?? \"\"),\n enabled: !!collectionId,\n queryFn: () => client.context.entries.list(collectionId as string),\n });\n}\n\n/** Every doc visible to the caller (collection-less included) — the pin picker's source. */\nexport function useAgentAllContextEntriesQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentAllContextEntriesKey(),\n queryFn: () => client.contextEntries.list({}),\n });\n}\n\nexport function useAgentModelRoutesQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentModelRoutesKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelRoutes(client, projectId as string),\n });\n}\n\nexport function useAgentSettingsQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: agentSettingsKey(),\n queryFn: () => client.console.storage.settings.get(),\n });\n}\n\nexport function usePatchAgentSettings() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (patch: Parameters<W6WClient[\"console\"][\"storage\"][\"settings\"][\"patch\"]>[0]) =>\n client.console.storage.settings.patch(patch),\n onSuccess: (s) => {\n qc.setQueryData(agentSettingsKey(), s);\n },\n });\n}\n\nexport function useStorageBindingsQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: storageBindingsKey(),\n queryFn: () => client.console.storage.bindings.list(),\n });\n}\n\n// ── the agent Test box (POST /agents/:id/test) ───────────────────────────────\n\n/** One message of a Test conversation, as the model contract has it. */\nexport interface AgentTestTurn {\n role: \"user\" | \"assistant\";\n content: unknown;\n}\n\nexport interface AgentTestRequest {\n project: string;\n message: string;\n /** The `turns` of earlier answers, so a follow-up keeps the conversation. */\n history?: AgentTestTurn[];\n /** Unsaved form state laid over the stored agent. */\n draft?: {\n instructions?: string;\n modelRouteId?: string | null;\n modelOptions?: Record<string, unknown>;\n tools?: AgentTool[];\n };\n}\n\nexport interface AgentTestToolCall {\n tool: string;\n input: Record<string, unknown>;\n ok: boolean;\n /** The tool's output, or the error message when `ok` is false. */\n output: unknown;\n}\n\nexport interface AgentTestResult {\n text: string;\n turns: AgentTestTurn[];\n toolCalls: AgentTestToolCall[];\n model: string | null;\n rounds: number;\n usage: { inputTokens: number; outputTokens: number };\n finishReason: string | null;\n}\n\n/**\n * Run the agent once on a message through the server's agent runtime — the same one a workflow's\n * \"Run agent\" step uses, so tools run there (fixed values resolved server-side, only the AI fields\n * passed on). Real, billed model and tool calls. Through `client.request` (Studio-internal route).\n */\nexport async function testAgent(\n client: W6WClient,\n id: string,\n body: AgentTestRequest,\n): Promise<AgentTestResult> {\n const res = await client.request<AgentTestResult>({\n method: \"POST\",\n path: path`/agents/${id}/test`,\n body,\n });\n return res.body;\n}\n\nexport function useTestAgentMutation(id: string) {\n const client = useEmbedClient();\n return useMutation({ mutationFn: (body: AgentTestRequest) => testAgent(client, id, body) });\n}\n","/**\n * Agents Studio asset hooks — skills, context collections/entries and stored asset files over\n * `W6WClient`'s `skills.*`, `context.*` and `assets.*` (react-query, same shape as `vars.ts`).\n *\n * These are tenant/account-scoped (no `project` is sent). Uploads are byte-mode: the caller\n * hashes and PUTs the same bytes (see Studio's `agents-studio/upload.ts`); this module only\n * wraps the single-call operations.\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type {\n AssetUploadCreateInput,\n CreateContextCollectionInput,\n CreateStandaloneContextEntryInput,\n UpdateContextEntryInput,\n} from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\n\nexport const skillsKey = (includeArchived = false) => [\"skills\", { includeArchived }] as const;\nexport const skillKey = (id: string) => [\"skills\", id] as const;\nexport const skillVersionsKey = (id: string) => [\"skills\", id, \"versions\"] as const;\nexport const contextCollectionsKey = (includeArchived = false) =>\n [\"context-collections\", { includeArchived }] as const;\nexport const contextCollectionKey = (id: string) => [\"context-collections\", id] as const;\nexport const contextEntriesKey = (id: string, includeArchived = false) =>\n [\"context-collections\", id, \"entries\", { includeArchived }] as const;\nexport const allContextEntriesKey = (includeArchived = false) =>\n [\"context-entries\", { includeArchived }] as const;\nexport const assetVersionsKey = (id: string) => [\"assets\", id, \"versions\"] as const;\nexport const assetFilesKey = (id: string, versionId: string) =>\n [\"assets\", id, \"versions\", versionId, \"files\"] as const;\n\n// ── Skills ──────────────────────────────────────────────────────────────────────────────────\n\nexport function useSkillsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillsKey(includeArchived),\n queryFn: () => client.skills.list({ includeArchived }),\n });\n}\n\nexport function useSkillQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.skills.get(id as string),\n });\n}\n\nexport function useSkillVersionsQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: skillVersionsKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.skills.versions(id as string),\n });\n}\n\nexport function useArchiveSkillMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.skills.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"skills\"] }),\n });\n}\n\n// ── Context collections + entries ───────────────────────────────────────────────────────────\n\nexport function useContextCollectionsQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextCollectionsKey(includeArchived),\n queryFn: () => client.context.list({ includeArchived }),\n });\n}\n\nexport function useContextCollectionQuery(id: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextCollectionKey(id ?? \"\"),\n enabled: id != null,\n queryFn: () => client.context.get(id as string),\n });\n}\n\nexport function useCreateContextCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateContextCollectionInput) => client.context.create(input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"context-collections\"] }),\n });\n}\n\nexport function useContextEntriesQuery(collectionId: string | undefined, includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: contextEntriesKey(collectionId ?? \"\", includeArchived),\n enabled: collectionId != null,\n queryFn: () => client.context.entries.list(collectionId as string, { includeArchived }),\n });\n}\n\n/** Edit-as-new-version: `PUT` creates the next version; `ifUnmodifiedSince` guards a stale edit. */\nexport function useUpdateContextEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: {\n collectionId: string;\n entryId: string;\n input: UpdateContextEntryInput;\n ifUnmodifiedSince?: string;\n }) =>\n client.context.entries.update(v.collectionId, v.entryId, v.input, {\n ifUnmodifiedSince: v.ifUnmodifiedSince,\n }),\n onSuccess: (_r, v) => {\n qc.invalidateQueries({ queryKey: [\"context-collections\", v.collectionId] });\n qc.invalidateQueries({ queryKey: [\"assets\"] });\n },\n });\n}\n\n// ── Collection-independent entries (`client.contextEntries.*`) ──────────────────────────────\n\n/** Every doc visible to the caller, whether or not it is in a collection. */\nexport function useAllContextEntriesQuery(includeArchived = false) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: allContextEntriesKey(includeArchived),\n queryFn: () => client.contextEntries.list({ includeArchived }),\n });\n}\n\n/** Invalidate the all-docs list and, per affected collection, its entries list. */\nfunction invalidateEntries(qc: ReturnType<typeof useQueryClient>, collectionIds: string[] = []) {\n qc.invalidateQueries({ queryKey: [\"context-entries\"] });\n for (const id of collectionIds) qc.invalidateQueries({ queryKey: contextEntriesKey(id) });\n}\n\n/** Create a text doc, private unless `collectionIds` / `visibility` say otherwise. */\nexport function useCreateContextEntryMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (input: CreateStandaloneContextEntryInput) => client.contextEntries.create(input),\n onSuccess: (_r, v) => invalidateEntries(qc, v.collectionIds),\n });\n}\n\nexport function useAddEntryToCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { entryId: string; collectionId: string }) =>\n client.contextEntries.addToCollection(v.entryId, v.collectionId),\n onSuccess: (_r, v) => invalidateEntries(qc, [v.collectionId]),\n });\n}\n\nexport function useRemoveEntryFromCollectionMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { entryId: string; collectionId: string }) =>\n client.contextEntries.removeFromCollection(v.entryId, v.collectionId),\n onSuccess: (_r, v) => invalidateEntries(qc, [v.collectionId]),\n });\n}\n\n// ── Asset versions, files, downloads ────────────────────────────────────────────────────────\n\nexport function useAssetVersionsQuery(assetId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: assetVersionsKey(assetId ?? \"\"),\n enabled: assetId != null,\n queryFn: () => client.assets.versions(assetId as string),\n });\n}\n\nexport function useAssetFilesQuery(assetId: string | undefined, versionId: string | undefined) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: assetFilesKey(assetId ?? \"\", versionId ?? \"\"),\n enabled: assetId != null && versionId != null,\n queryFn: () => client.assets.files(assetId as string, versionId as string),\n });\n}\n\n/** Exact bytes of one file. A mutation (not a query): downloads are user-triggered, never cached. */\nexport function useDownloadAssetFileMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { assetId: string; versionId: string; fileId: string }) =>\n client.assets.content(v.assetId, v.versionId, v.fileId),\n });\n}\n\n/** One version as a store-only ZIP. */\nexport function useDownloadAssetArchiveMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { assetId: string; versionId: string }) =>\n client.assets.archiveDownload(v.assetId, v.versionId),\n });\n}\n\nexport function useArchiveAssetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => client.assets.archive(id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"assets\"] }),\n });\n}\n\n// ── Upload (resumable, byte-mode) ───────────────────────────────────────────────────────────\n\nexport function useCreateAssetUploadMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (input: AssetUploadCreateInput) => client.assets.uploads.create(input),\n });\n}\n\nexport function usePutAssetUploadEntryMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { uploadId: string; index: number; bytes: Uint8Array }) =>\n client.assets.uploads.putEntry(v.uploadId, v.index, v.bytes),\n });\n}\n\n/** Publishing a version changes skills, context and assets alike — invalidate all three. */\nexport function useFinalizeAssetUploadMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (uploadId: string) => client.assets.uploads.finalize(uploadId),\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: [\"skills\"] });\n qc.invalidateQueries({ queryKey: [\"context-collections\"] });\n qc.invalidateQueries({ queryKey: [\"assets\"] });\n },\n });\n}\n\nexport function useAbortAssetUploadMutation() {\n const client = useEmbedClient();\n return useMutation({ mutationFn: (uploadId: string) => client.assets.uploads.abort(uploadId) });\n}\n"],"names":["AgentConflictError","cause","__publicField","currentRevisionOf","raw","o","v","_a","_c","_b","isAgentConflict","agentsKey","includeArchived","agentKey","id","agentSkillVersionsKey","skillId","agentSkillsKey","agentContextKey","agentContextEntriesKey","collectionId","agentAllContextEntriesKey","agentModelRoutesKey","projectId","agentSettingsKey","storageBindingsKey","updateAgent","client","patch","loaded","e","ApiError","skillPinState","pin","readyVersions","contextPinState","entries","readyContextEntries","useAgentsQuery","useEmbedClient","useQuery","useAgentQuery","useCreateAgent","qc","useQueryClient","useMutation","input","useUpdateAgent","agent","useArchiveAgent","useAgentSkillsQuery","useAgentSkillVersionsQuery","useAgentContextCollectionsQuery","useAgentContextEntriesQuery","useAgentAllContextEntriesQuery","useAgentModelRoutesQuery","listModelRoutes","useAgentSettingsQuery","usePatchAgentSettings","useStorageBindingsQuery","testAgent","body","path","useTestAgentMutation","skillsKey","skillKey","skillVersionsKey","contextCollectionsKey","contextCollectionKey","contextEntriesKey","allContextEntriesKey","assetVersionsKey","assetFilesKey","versionId","useSkillsQuery","useSkillQuery","useSkillVersionsQuery","useArchiveSkillMutation","useContextCollectionsQuery","useContextCollectionQuery","useCreateContextCollectionMutation","useContextEntriesQuery","useUpdateContextEntryMutation","_r","useAllContextEntriesQuery","invalidateEntries","collectionIds","useCreateContextEntryMutation","useAddEntryToCollectionMutation","useRemoveEntryFromCollectionMutation","useAssetVersionsQuery","assetId","useAssetFilesQuery","useDownloadAssetFileMutation","useDownloadAssetArchiveMutation","useArchiveAssetMutation","useCreateAssetUploadMutation","usePutAssetUploadEntryMutation","useFinalizeAssetUploadMutation","uploadId","useAbortAssetUploadMutation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCO,MAAMA,UAA2B,MAAM;AAAA,EAK5C,YAAYC,GAAiB;AAC3B,UAAM,kEAAkE;AALjE,IAAAC,EAAA,cAAO;AAEP;AAAA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAGP,SAAK,OAAO,sBACZ,KAAK,QAAQD,GACb,KAAK,kBAAkBE,EAAkBF,EAAM,GAAG;AAAA,EACpD;AACF;AAEA,SAASE,EAAkBC,GAA6B;;AACtD,QAAMC,IAAID,GAIJE,KAAID,KAAA,gBAAAA,EAAG,eAAYE,IAAAF,KAAA,gBAAAA,EAAG,UAAH,gBAAAE,EAAU,eAAYC,KAAAC,IAAAJ,KAAA,gBAAAA,EAAG,UAAH,gBAAAI,EAAU,YAAV,gBAAAD,EAAmB;AAClE,SAAO,OAAOF,KAAM,WAAWA,IAAI;AACrC;AAGO,SAASI,EAAgB,GAAqC;AACnE,SAAO,aAAaV;AACtB;AAEO,MAAMW,IAAY,CAACC,IAAkB,OAAU,CAAC,UAAU,EAAE,iBAAAA,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AC/C,QAAMvE,IAASY,EAAA,GACTI,IAAKC,EAAA;AACX,SAAOC,EAAY;AAAA,IACjB,YAAY,CAACsD,MAAqBxE,EAAO,OAAO,QAAQ,SAASwE,CAAQ;AAAA,IACzE,WAAW,MAAM;AACf,MAAAxD,EAAG,kBAAkB,EAAE,UAAU,CAAC,QAAQ,GAAG,GAC7CA,EAAG,kBAAkB,EAAE,UAAU,CAAC,qBAAqB,GAAG,GAC1DA,EAAG,kBAAkB,EAAE,UAAU,CAAC,QAAQ,GAAG;AAAA,IAC/C;AAAA,EAAA,CACD;AACH;AAEO,SAASyD,KAA8B;AAC5C,QAAMzE,IAASY,EAAA;AACf,SAAOM,EAAY,EAAE,YAAY,CAACsD,MAAqBxE,EAAO,OAAO,QAAQ,MAAMwE,CAAQ,GAAG;AAChG;"}
@@ -0,0 +1,37 @@
1
+ const n = "Untitled workflow";
2
+ function l(t) {
3
+ const e = n.toLowerCase();
4
+ let a = !1, s = 1;
5
+ for (const o of t) {
6
+ const i = (o ?? "").trim().toLowerCase();
7
+ if (i === e) a = !0;
8
+ else if (i.startsWith(`${e} `)) {
9
+ const r = Number(i.slice(e.length + 1));
10
+ Number.isInteger(r) && r > 0 && (a = !0, s = Math.max(s, r));
11
+ }
12
+ }
13
+ return a ? `${n} ${s + 1}` : n;
14
+ }
15
+ function u(t, e = n) {
16
+ return {
17
+ manifestVersion: "2",
18
+ id: t,
19
+ name: t,
20
+ displayName: e,
21
+ trigger: { type: "manual" },
22
+ nodes: [
23
+ {
24
+ id: "manual_trigger_1",
25
+ uses: { app: "@w6w/trigger", action: "manual" },
26
+ with: { fields: [] },
27
+ position: { x: 80, y: 80 }
28
+ }
29
+ ]
30
+ };
31
+ }
32
+ export {
33
+ n as U,
34
+ u as b,
35
+ l as n
36
+ };
37
+ //# sourceMappingURL=workflow-blank-BJFLdGyE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-blank-BJFLdGyE.js","sources":["../src/lib/workflow-blank.ts"],"sourcesContent":["export const UNTITLED_WORKFLOW = \"Untitled workflow\";\n\n/**\n * The name a new workflow gets: \"Untitled workflow\", or — when that is taken — the next number\n * after the highest \"Untitled workflow N\" in `taken`, so a list of new workflows reads 1, 2, 3\n * instead of the same name over and over. Names are compared case-insensitively, trimmed.\n */\nexport function nextUntitledName(taken: Iterable<string | null | undefined>): string {\n const base = UNTITLED_WORKFLOW.toLowerCase();\n let used = false;\n let max = 1;\n for (const raw of taken) {\n const name = (raw ?? \"\").trim().toLowerCase();\n if (name === base) used = true;\n else if (name.startsWith(`${base} `)) {\n const n = Number(name.slice(base.length + 1));\n if (Number.isInteger(n) && n > 0) {\n used = true;\n max = Math.max(max, n);\n }\n }\n }\n return used ? `${UNTITLED_WORKFLOW} ${max + 1}` : UNTITLED_WORKFLOW;\n}\n\n/**\n * A fresh, minimal workflow definition for a brand-new id (a new object on every call). Pass\n * `displayName` (from {@link nextUntitledName}) so a new workflow does not repeat an existing name.\n */\nexport function blankDefinition(\n id: string,\n displayName: string = UNTITLED_WORKFLOW,\n): Record<string, unknown> {\n // Every workflow starts with a manual trigger (rfcs/node-types.md \"Triggers as nodes\"). The\n // `trigger` field says how a run is launched; the canvas draws only the `@w6w/trigger` NODE, so\n // without it a new workflow opened on an empty canvas. The node is an ordinary one — the author\n // can replace it with another trigger or delete it — and is shaped exactly as the editor mints a\n // Manual trigger from the picker (`manual_trigger_1`, `fields: []`, a position).\n return {\n manifestVersion: \"2\",\n id,\n name: id,\n displayName,\n trigger: { type: \"manual\" },\n nodes: [\n {\n id: \"manual_trigger_1\",\n uses: { app: \"@w6w/trigger\", action: \"manual\" },\n with: { fields: [] },\n position: { x: 80, y: 80 },\n },\n ],\n };\n}\n"],"names":["UNTITLED_WORKFLOW","nextUntitledName","taken","base","used","max","raw","name","n","blankDefinition","id","displayName"],"mappings":"AAAO,MAAMA,IAAoB;AAO1B,SAASC,EAAiBC,GAAoD;AACnF,QAAMC,IAAOH,EAAkB,YAAA;AAC/B,MAAII,IAAO,IACPC,IAAM;AACV,aAAWC,KAAOJ,GAAO;AACvB,UAAMK,KAAQD,KAAO,IAAI,KAAA,EAAO,YAAA;AAChC,QAAIC,MAASJ,EAAM,CAAAC,IAAO;AAAA,aACjBG,EAAK,WAAW,GAAGJ,CAAI,GAAG,GAAG;AACpC,YAAMK,IAAI,OAAOD,EAAK,MAAMJ,EAAK,SAAS,CAAC,CAAC;AAC5C,MAAI,OAAO,UAAUK,CAAC,KAAKA,IAAI,MAC7BJ,IAAO,IACPC,IAAM,KAAK,IAAIA,GAAKG,CAAC;AAAA,IAEzB;AAAA,EACF;AACA,SAAOJ,IAAO,GAAGJ,CAAiB,IAAIK,IAAM,CAAC,KAAKL;AACpD;AAMO,SAASS,EACdC,GACAC,IAAsBX,GACG;AAMzB,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB,IAAAU;AAAA,IACA,MAAMA;AAAA,IACN,aAAAC;AAAA,IACA,SAAS,EAAE,MAAM,SAAA;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,QACE,IAAI;AAAA,QACJ,MAAM,EAAE,KAAK,gBAAgB,QAAQ,SAAA;AAAA,QACrC,MAAM,EAAE,QAAQ,GAAC;AAAA,QACjB,UAAU,EAAE,GAAG,IAAI,GAAG,GAAA;AAAA,MAAG;AAAA,IAC3B;AAAA,EACF;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w6w/embed",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "Embed w6w's managed editor and providers in a host React app.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "repository": {
@@ -76,7 +76,7 @@
76
76
  "@w6w/react": "^0.9.15",
77
77
  "@w6w/sdk": "^0.9.30",
78
78
  "@w6w/expr": "^0.1.3",
79
- "@w6w/ui": "^0.2.59",
79
+ "@w6w/ui": "^0.2.60",
80
80
  "yaml": "^2.4.2"
81
81
  },
82
82
  "peerDependencies": {
@@ -1,21 +0,0 @@
1
- function n(i) {
2
- return {
3
- manifestVersion: "2",
4
- id: i,
5
- name: i,
6
- displayName: "Untitled workflow",
7
- trigger: { type: "manual" },
8
- nodes: [
9
- {
10
- id: "manual_trigger_1",
11
- uses: { app: "@w6w/trigger", action: "manual" },
12
- with: { fields: [] },
13
- position: { x: 80, y: 80 }
14
- }
15
- ]
16
- };
17
- }
18
- export {
19
- n as b
20
- };
21
- //# sourceMappingURL=workflow-blank-CorOIrSj.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"workflow-blank-CorOIrSj.js","sources":["../src/lib/workflow-blank.ts"],"sourcesContent":["/** A fresh, minimal workflow definition for a brand-new id (a new object on every call). */\nexport function blankDefinition(id: string): Record<string, unknown> {\n // Every workflow starts with a manual trigger (rfcs/node-types.md \"Triggers as nodes\"). The\n // `trigger` field says how a run is launched; the canvas draws only the `@w6w/trigger` NODE, so\n // without it a new workflow opened on an empty canvas. The node is an ordinary one — the author\n // can replace it with another trigger or delete it — and is shaped exactly as the editor mints a\n // Manual trigger from the picker (`manual_trigger_1`, `fields: []`, a position).\n return {\n manifestVersion: \"2\",\n id,\n name: id,\n displayName: \"Untitled workflow\",\n trigger: { type: \"manual\" },\n nodes: [\n {\n id: \"manual_trigger_1\",\n uses: { app: \"@w6w/trigger\", action: \"manual\" },\n with: { fields: [] },\n position: { x: 80, y: 80 },\n },\n ],\n };\n}\n"],"names":["blankDefinition","id"],"mappings":"AACO,SAASA,EAAgBC,GAAqC;AAMnE,SAAO;AAAA,IACL,iBAAiB;AAAA,IACjB,IAAAA;AAAA,IACA,MAAMA;AAAA,IACN,aAAa;AAAA,IACb,SAAS,EAAE,MAAM,SAAA;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,QACE,IAAI;AAAA,QACJ,MAAM,EAAE,KAAK,gBAAgB,QAAQ,SAAA;AAAA,QACrC,MAAM,EAAE,QAAQ,GAAC;AAAA,QACjB,UAAU,EAAE,GAAG,IAAI,GAAG,GAAA;AAAA,MAAG;AAAA,IAC3B;AAAA,EACF;AAEJ;"}